@mento-protocol/mento-sdk 1.17.0 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/README.md +19 -19
  2. package/package.json +1 -1
  3. package/dist/cjs/ChainClient.d.ts +0 -9
  4. package/dist/cjs/ChainClient.js +0 -58
  5. package/dist/cjs/TestChainClient.d.ts +0 -7
  6. package/dist/cjs/TestChainClient.js +0 -41
  7. package/dist/cjs/constants/addresses.d.ts +0 -4
  8. package/dist/cjs/constants/addresses.js +0 -80
  9. package/dist/cjs/constants/currencies.d.ts +0 -5
  10. package/dist/cjs/constants/currencies.js +0 -29
  11. package/dist/cjs/constants/index.d.ts +0 -4
  12. package/dist/cjs/constants/index.js +0 -20
  13. package/dist/cjs/constants/tokens.11142220.d.ts +0 -2
  14. package/dist/cjs/constants/tokens.11142220.js +0 -128
  15. package/dist/cjs/constants/tokens.42220.d.ts +0 -2
  16. package/dist/cjs/constants/tokens.42220.js +0 -128
  17. package/dist/cjs/constants/tokens.44787.d.ts +0 -2
  18. package/dist/cjs/constants/tokens.44787.js +0 -128
  19. package/dist/cjs/constants/tokens.d.ts +0 -50
  20. package/dist/cjs/constants/tokens.js +0 -155
  21. package/dist/cjs/constants/tradablePairs.11142220.d.ts +0 -2
  22. package/dist/cjs/constants/tradablePairs.11142220.js +0 -7391
  23. package/dist/cjs/constants/tradablePairs.42220.d.ts +0 -2
  24. package/dist/cjs/constants/tradablePairs.42220.js +0 -7391
  25. package/dist/cjs/constants/tradablePairs.44787.d.ts +0 -2
  26. package/dist/cjs/constants/tradablePairs.44787.js +0 -7391
  27. package/dist/cjs/constants/tradablePairs.d.ts +0 -16
  28. package/dist/cjs/constants/tradablePairs.js +0 -53
  29. package/dist/cjs/enums/chainId.d.ts +0 -5
  30. package/dist/cjs/enums/chainId.js +0 -9
  31. package/dist/cjs/enums/index.d.ts +0 -3
  32. package/dist/cjs/enums/index.js +0 -19
  33. package/dist/cjs/enums/proposalState.d.ts +0 -10
  34. package/dist/cjs/enums/proposalState.js +0 -14
  35. package/dist/cjs/enums/tradingMode.d.ts +0 -17
  36. package/dist/cjs/enums/tradingMode.js +0 -21
  37. package/dist/cjs/governance.d.ts +0 -62
  38. package/dist/cjs/governance.js +0 -151
  39. package/dist/cjs/index.d.ts +0 -7
  40. package/dist/cjs/index.js +0 -23
  41. package/dist/cjs/interfaces/IChainClient.d.ts +0 -6
  42. package/dist/cjs/interfaces/IChainClient.js +0 -2
  43. package/dist/cjs/interfaces/index.d.ts +0 -4
  44. package/dist/cjs/interfaces/index.js +0 -20
  45. package/dist/cjs/interfaces/tradingLimit.d.ts +0 -7
  46. package/dist/cjs/interfaces/tradingLimit.js +0 -2
  47. package/dist/cjs/interfaces/tradingLimitsConfig.d.ts +0 -10
  48. package/dist/cjs/interfaces/tradingLimitsConfig.js +0 -2
  49. package/dist/cjs/interfaces/tradingLimitsState.d.ts +0 -9
  50. package/dist/cjs/interfaces/tradingLimitsState.js +0 -2
  51. package/dist/cjs/limits.d.ts +0 -33
  52. package/dist/cjs/limits.js +0 -130
  53. package/dist/cjs/mento.d.ts +0 -287
  54. package/dist/cjs/mento.js +0 -699
  55. package/dist/cjs/routeUtils.d.ts +0 -304
  56. package/dist/cjs/routeUtils.js +0 -372
  57. package/dist/cjs/types/contractAddressMap.d.ts +0 -4
  58. package/dist/cjs/types/contractAddressMap.js +0 -2
  59. package/dist/cjs/types/contractAddresses.d.ts +0 -23
  60. package/dist/cjs/types/contractAddresses.js +0 -2
  61. package/dist/cjs/types/index.d.ts +0 -2
  62. package/dist/cjs/types/index.js +0 -18
  63. package/dist/cjs/utils.d.ts +0 -80
  64. package/dist/cjs/utils.js +0 -177
  65. package/dist/esm/ChainClient.d.ts +0 -9
  66. package/dist/esm/ChainClient.js +0 -54
  67. package/dist/esm/TestChainClient.d.ts +0 -7
  68. package/dist/esm/TestChainClient.js +0 -37
  69. package/dist/esm/constants/addresses.d.ts +0 -4
  70. package/dist/esm/constants/addresses.js +0 -76
  71. package/dist/esm/constants/currencies.d.ts +0 -5
  72. package/dist/esm/constants/currencies.js +0 -26
  73. package/dist/esm/constants/index.d.ts +0 -4
  74. package/dist/esm/constants/index.js +0 -4
  75. package/dist/esm/constants/tokens.11142220.d.ts +0 -2
  76. package/dist/esm/constants/tokens.11142220.js +0 -125
  77. package/dist/esm/constants/tokens.42220.d.ts +0 -2
  78. package/dist/esm/constants/tokens.42220.js +0 -125
  79. package/dist/esm/constants/tokens.44787.d.ts +0 -2
  80. package/dist/esm/constants/tokens.44787.js +0 -125
  81. package/dist/esm/constants/tokens.d.ts +0 -50
  82. package/dist/esm/constants/tokens.js +0 -127
  83. package/dist/esm/constants/tradablePairs.11142220.d.ts +0 -2
  84. package/dist/esm/constants/tradablePairs.11142220.js +0 -7388
  85. package/dist/esm/constants/tradablePairs.42220.d.ts +0 -2
  86. package/dist/esm/constants/tradablePairs.42220.js +0 -7388
  87. package/dist/esm/constants/tradablePairs.44787.d.ts +0 -2
  88. package/dist/esm/constants/tradablePairs.44787.js +0 -7388
  89. package/dist/esm/constants/tradablePairs.d.ts +0 -16
  90. package/dist/esm/constants/tradablePairs.js +0 -26
  91. package/dist/esm/enums/chainId.d.ts +0 -5
  92. package/dist/esm/enums/chainId.js +0 -6
  93. package/dist/esm/enums/index.d.ts +0 -3
  94. package/dist/esm/enums/index.js +0 -3
  95. package/dist/esm/enums/proposalState.d.ts +0 -10
  96. package/dist/esm/enums/proposalState.js +0 -11
  97. package/dist/esm/enums/tradingMode.d.ts +0 -17
  98. package/dist/esm/enums/tradingMode.js +0 -18
  99. package/dist/esm/governance.d.ts +0 -62
  100. package/dist/esm/governance.js +0 -147
  101. package/dist/esm/index.d.ts +0 -7
  102. package/dist/esm/index.js +0 -7
  103. package/dist/esm/interfaces/IChainClient.d.ts +0 -6
  104. package/dist/esm/interfaces/IChainClient.js +0 -1
  105. package/dist/esm/interfaces/index.d.ts +0 -4
  106. package/dist/esm/interfaces/index.js +0 -4
  107. package/dist/esm/interfaces/tradingLimit.d.ts +0 -7
  108. package/dist/esm/interfaces/tradingLimit.js +0 -1
  109. package/dist/esm/interfaces/tradingLimitsConfig.d.ts +0 -10
  110. package/dist/esm/interfaces/tradingLimitsConfig.js +0 -1
  111. package/dist/esm/interfaces/tradingLimitsState.d.ts +0 -9
  112. package/dist/esm/interfaces/tradingLimitsState.js +0 -1
  113. package/dist/esm/limits.d.ts +0 -33
  114. package/dist/esm/limits.js +0 -123
  115. package/dist/esm/mento.d.ts +0 -287
  116. package/dist/esm/mento.js +0 -671
  117. package/dist/esm/routeUtils.d.ts +0 -304
  118. package/dist/esm/routeUtils.js +0 -362
  119. package/dist/esm/types/contractAddressMap.d.ts +0 -4
  120. package/dist/esm/types/contractAddressMap.js +0 -1
  121. package/dist/esm/types/contractAddresses.d.ts +0 -23
  122. package/dist/esm/types/contractAddresses.js +0 -1
  123. package/dist/esm/types/index.d.ts +0 -2
  124. package/dist/esm/types/index.js +0 -2
  125. package/dist/esm/utils.d.ts +0 -80
  126. package/dist/esm/utils.js +0 -162
@@ -1,23 +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
- MentoRouter: string;
10
- Broker: string;
11
- BiPoolManager: string;
12
- BreakerBox: string;
13
- Reserve: string;
14
- ConstantSumPricingModule: string;
15
- ConstantProductPricingModule: string;
16
- MedianDeltaBreaker: string;
17
- ValueDeltaBreaker: string;
18
- StableToken: string;
19
- StableTokenEUR: string;
20
- StableTokenBRL: string;
21
- StableTokenXOF: string;
22
- SortedOracles: string;
23
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- export * from './contractAddresses';
2
- export * from './contractAddressMap';
@@ -1,2 +0,0 @@
1
- export * from './contractAddresses';
2
- export * from './contractAddressMap';
@@ -1,80 +0,0 @@
1
- import { BigNumberish, providers, Signer } from 'ethers';
2
- import { TokenSymbol } from './constants';
3
- import { Address } from './interfaces';
4
- import { Token, TradablePair } from './mento';
5
- /**
6
- * Gets the chain ID from a signer or provider
7
- * @param signerOrProvider an ethers provider or signer
8
- * @returns the chain ID
9
- */
10
- export declare function getChainId(signerOrProvider: Signer | providers.Provider): Promise<number>;
11
- /**
12
- * Ensures that given signer is truly a a connected signer
13
- * @param signer an ethers signer
14
- * @throws if signer is invalid or not connected
15
- */
16
- export declare function validateSigner(signer: Signer): void;
17
- /**
18
- * Ensures that given signerOrProvider is truly a provider or a connected signer
19
- * @param signerOrProvider an ethers provider or signer
20
- * @throws if signerOrProvider is invalid or not connected
21
- */
22
- export declare function validateSignerOrProvider(signerOrProvider: Signer | providers.Provider): void;
23
- /**
24
- * Returns the symbol of an erc20 token
25
- * @param tokenAddr the address of the erc20 token
26
- * @param signerOrProvider an ethers provider or signer
27
- * @returns the symbol of the erc20 token
28
- */
29
- export declare function getSymbolFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<TokenSymbol>;
30
- /**
31
- * Returns the name of an erc20 token
32
- * @param tokenAddr the address of the erc20 token
33
- * @param signerOrProvider an ethers provider or signer
34
- * @returns the name of the erc20 token
35
- */
36
- export declare function getNameFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<string>;
37
- /**
38
- * Returns the decimals of an erc20 token
39
- * @param tokenAddr the address of the erc20 token
40
- * @param signerOrProvider an ethers provider or signer
41
- * @returns the decimals of the erc20 token
42
- */
43
- export declare function getDecimalsFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<number>;
44
- /**
45
- * Returns a populated tx obj for increasing the allowance of a spender for a given erc20 token by a given amount
46
- * @param tokenAddr the address of the erc20 token
47
- * @param spender the address of the spender
48
- * @param amount the amount to increase the allowance by
49
- * @param signerOrProvider an ethers signer or provider
50
- * @returns the populated TransactionRequest object
51
- */
52
- export declare function increaseAllowance(tokenAddr: string, spender: string, amount: BigNumberish, signerOrProvider: Signer | providers.Provider): Promise<providers.TransactionRequest>;
53
- /**
54
- * Find a token address by its symbol from tradable pairs
55
- * @param pairs array of tradable pairs to search through
56
- * @param symbol the token symbol to find (case-insensitive)
57
- * @returns the token address if found, null otherwise
58
- */
59
- export declare function findTokenAddressBySymbolInTradablePairs(symbol: TokenSymbol, pairs: readonly TradablePair[]): Address | null;
60
- export declare function capitalize(str: string): string; /**
61
- * Helper function to get token address by symbol for a specific chain
62
- * @param symbol - The token symbol
63
- * @param chainId - The chain ID
64
- * @returns The token address or undefined if not found
65
- */
66
- export declare function getTokenAddress(symbol: TokenSymbol, chainId: number): string | undefined;
67
- /**
68
- * Helper function to find a token by symbol in the cached tokens
69
- * @param symbol - The token symbol to search for
70
- * @param chainId - The chain ID
71
- * @returns The token object or undefined if not found
72
- */
73
- export declare function findTokenBySymbol(symbol: string, chainId: number): Token | undefined;
74
- /**
75
- * Computes the rate feed ID from a rate feed identifier string.
76
- * This follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
77
- * @param rateFeed the rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
78
- * @returns the computed rate feed address
79
- */
80
- export declare function toRateFeedId(rateFeed: string): Address;
package/dist/esm/utils.js DELETED
@@ -1,162 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { Contract, ethers, providers, Signer } from 'ethers';
11
- import { getCachedTokensSync, TOKEN_ADDRESSES_BY_CHAIN } from './constants/tokens';
12
- /**
13
- * Gets the chain ID from a signer or provider
14
- * @param signerOrProvider an ethers provider or signer
15
- * @returns the chain ID
16
- */
17
- export function getChainId(signerOrProvider) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- const provider = Signer.isSigner(signerOrProvider)
20
- ? signerOrProvider.provider
21
- : signerOrProvider;
22
- return (yield provider.getNetwork()).chainId;
23
- });
24
- }
25
- /**
26
- * Ensures that given signer is truly a a connected signer
27
- * @param signer an ethers signer
28
- * @throws if signer is invalid or not connected
29
- */
30
- export function validateSigner(signer) {
31
- if (!Signer.isSigner(signer)) {
32
- throw new Error('A valid signer must be provided');
33
- }
34
- if (!providers.Provider.isProvider(signer.provider)) {
35
- throw new Error('Signer must be connected to a provider');
36
- }
37
- }
38
- /**
39
- * Ensures that given signerOrProvider is truly a provider or a connected signer
40
- * @param signerOrProvider an ethers provider or signer
41
- * @throws if signerOrProvider is invalid or not connected
42
- */
43
- export function validateSignerOrProvider(signerOrProvider) {
44
- const isSigner = Signer.isSigner(signerOrProvider);
45
- const isProvider = providers.Provider.isProvider(signerOrProvider);
46
- if (!isSigner && !isProvider) {
47
- throw new Error('A valid signer or provider must be provided');
48
- }
49
- if (isSigner && !providers.Provider.isProvider(signerOrProvider.provider)) {
50
- throw new Error('Signer must be connected to a provider');
51
- }
52
- }
53
- /**
54
- * Returns the symbol of an erc20 token
55
- * @param tokenAddr the address of the erc20 token
56
- * @param signerOrProvider an ethers provider or signer
57
- * @returns the symbol of the erc20 token
58
- */
59
- export function getSymbolFromTokenAddress(tokenAddr, signerOrProvider) {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- const erc20Abi = ['function symbol() external view returns (string memory)'];
62
- const contract = new Contract(tokenAddr, erc20Abi, signerOrProvider);
63
- return contract.symbol();
64
- });
65
- }
66
- /**
67
- * Returns the name of an erc20 token
68
- * @param tokenAddr the address of the erc20 token
69
- * @param signerOrProvider an ethers provider or signer
70
- * @returns the name of the erc20 token
71
- */
72
- export function getNameFromTokenAddress(tokenAddr, signerOrProvider) {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- const erc20Abi = ['function name() external view returns (string memory)'];
75
- const contract = new Contract(tokenAddr, erc20Abi, signerOrProvider);
76
- return contract.name();
77
- });
78
- }
79
- /**
80
- * Returns the decimals of an erc20 token
81
- * @param tokenAddr the address of the erc20 token
82
- * @param signerOrProvider an ethers provider or signer
83
- * @returns the decimals of the erc20 token
84
- */
85
- export function getDecimalsFromTokenAddress(tokenAddr, signerOrProvider) {
86
- return __awaiter(this, void 0, void 0, function* () {
87
- const erc20Abi = ['function decimals() external view returns (uint8)'];
88
- const contract = new Contract(tokenAddr, erc20Abi, signerOrProvider);
89
- return contract.decimals();
90
- });
91
- }
92
- /**
93
- * Returns a populated tx obj for increasing the allowance of a spender for a given erc20 token by a given amount
94
- * @param tokenAddr the address of the erc20 token
95
- * @param spender the address of the spender
96
- * @param amount the amount to increase the allowance by
97
- * @param signerOrProvider an ethers signer or provider
98
- * @returns the populated TransactionRequest object
99
- */
100
- export function increaseAllowance(tokenAddr, spender, amount, signerOrProvider) {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- const abi = [
103
- 'function increaseAllowance(address spender, uint256 value) external returns (bool)',
104
- ];
105
- // TODO, not all ERC-20 contracts support increaseAllowance
106
- // Add a check for that here
107
- const contract = new Contract(tokenAddr, abi, signerOrProvider);
108
- return yield contract.populateTransaction.increaseAllowance(spender, amount);
109
- });
110
- }
111
- /**
112
- * Find a token address by its symbol from tradable pairs
113
- * @param pairs array of tradable pairs to search through
114
- * @param symbol the token symbol to find (case-insensitive)
115
- * @returns the token address if found, null otherwise
116
- */
117
- export function findTokenAddressBySymbolInTradablePairs(symbol, pairs) {
118
- var _a, _b;
119
- return ((_b = (_a = pairs
120
- .flatMap((pair) => pair.assets)
121
- .find((asset) => asset.symbol.toLowerCase() === symbol.toLowerCase())) === null || _a === void 0 ? void 0 : _a.address) !== null && _b !== void 0 ? _b : null);
122
- }
123
- export function capitalize(str) {
124
- return str.charAt(0).toUpperCase() + str.slice(1);
125
- } /**
126
- * Helper function to get token address by symbol for a specific chain
127
- * @param symbol - The token symbol
128
- * @param chainId - The chain ID
129
- * @returns The token address or undefined if not found
130
- */
131
- export function getTokenAddress(symbol, chainId) {
132
- var _a;
133
- return (_a = TOKEN_ADDRESSES_BY_CHAIN[chainId]) === null || _a === void 0 ? void 0 : _a[symbol];
134
- }
135
- /**
136
- * Helper function to find a token by symbol in the cached tokens
137
- * @param symbol - The token symbol to search for
138
- * @param chainId - The chain ID
139
- * @returns The token object or undefined if not found
140
- */
141
- export function findTokenBySymbol(symbol, chainId) {
142
- const tokens = getCachedTokensSync(chainId);
143
- return tokens.find((token) => token.symbol === symbol);
144
- }
145
- /**
146
- * Computes the rate feed ID from a rate feed identifier string.
147
- * This follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
148
- * @param rateFeed the rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
149
- * @returns the computed rate feed address
150
- */
151
- export function toRateFeedId(rateFeed) {
152
- // 1. Calculate keccak256 hash
153
- const hashedBytes = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(rateFeed));
154
- // 2. Convert to BigInt (equivalent to uint256)
155
- const hashAsBigInt = BigInt(hashedBytes);
156
- // 3. Mask to 160 bits (equivalent to uint160)
157
- const maskedToUint160 = hashAsBigInt & ((BigInt(1) << BigInt(160)) - BigInt(1));
158
- // 4. Convert to address (hex string)
159
- const addressHex = '0x' + maskedToUint160.toString(16).padStart(40, '0');
160
- // 5. Return calculated rate feed ID
161
- return addressHex;
162
- }