@mento-protocol/mento-sdk 1.10.3 → 1.11.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.
- package/README.md +16 -18
- package/dist/cjs/constants/addresses.js +48 -32
- package/dist/cjs/constants/currencies.d.ts +5 -0
- package/dist/cjs/constants/currencies.js +29 -0
- package/dist/cjs/constants/index.d.ts +1 -0
- package/dist/cjs/constants/index.js +1 -0
- package/dist/cjs/constants/tradablePairs.11142220.d.ts +2 -0
- package/dist/cjs/constants/tradablePairs.11142220.js +7391 -0
- package/dist/cjs/constants/tradablePairs.42220.js +1 -1
- package/dist/cjs/constants/tradablePairs.44787.js +1 -1
- package/dist/cjs/enums/chainId.d.ts +3 -1
- package/dist/cjs/enums/chainId.js +2 -0
- package/dist/cjs/mento.d.ts +4 -0
- package/dist/cjs/mento.js +15 -1
- package/dist/cjs/types/contractAddressMap.d.ts +1 -1
- package/dist/cjs/utils.d.ts +1 -6
- package/dist/cjs/utils.js +5 -22
- package/dist/esm/constants/addresses.js +48 -32
- package/dist/esm/constants/currencies.d.ts +5 -0
- package/dist/esm/constants/currencies.js +26 -0
- package/dist/esm/constants/index.d.ts +1 -0
- package/dist/esm/constants/index.js +1 -0
- package/dist/esm/constants/tradablePairs.11142220.d.ts +2 -0
- package/dist/esm/constants/tradablePairs.11142220.js +7388 -0
- package/dist/esm/constants/tradablePairs.42220.js +1 -1
- package/dist/esm/constants/tradablePairs.44787.js +1 -1
- package/dist/esm/enums/chainId.d.ts +3 -1
- package/dist/esm/enums/chainId.js +2 -0
- package/dist/esm/mento.d.ts +4 -0
- package/dist/esm/mento.js +16 -2
- package/dist/esm/types/contractAddressMap.d.ts +1 -1
- package/dist/esm/utils.d.ts +1 -6
- package/dist/esm/utils.js +4 -21
- package/package.json +10 -7
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export var ChainId;
|
|
2
2
|
(function (ChainId) {
|
|
3
3
|
ChainId[ChainId["CELO"] = 42220] = "CELO";
|
|
4
|
+
ChainId[ChainId["CELO_SEPOLIA"] = 11142220] = "CELO_SEPOLIA";
|
|
4
5
|
ChainId[ChainId["ALFAJORES"] = 44787] = "ALFAJORES";
|
|
6
|
+
ChainId[ChainId["BASE"] = 8453] = "BASE";
|
|
5
7
|
})(ChainId || (ChainId = {}));
|
package/dist/esm/mento.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IBroker } from '@mento-protocol/mento-core-ts';
|
|
2
2
|
import { BigNumber, BigNumberish, providers, Signer } from 'ethers';
|
|
3
3
|
import { Address, TradingLimit, TradingLimitsConfig, TradingLimitsState } from './interfaces';
|
|
4
|
+
import { Identifier } from './constants/addresses';
|
|
4
5
|
import { TradablePairWithSpread } from './constants/tradablePairs';
|
|
5
6
|
export interface Exchange {
|
|
6
7
|
providerAddr: Address;
|
|
@@ -26,6 +27,7 @@ export declare class Mento {
|
|
|
26
27
|
private readonly broker;
|
|
27
28
|
private readonly router;
|
|
28
29
|
private exchanges;
|
|
30
|
+
private cachedChainId;
|
|
29
31
|
/**
|
|
30
32
|
* This constructor is private, use the static create or createWithParams methods
|
|
31
33
|
* to create a new Mento instance
|
|
@@ -235,4 +237,6 @@ export declare class Mento {
|
|
|
235
237
|
* @returns the trading limits state
|
|
236
238
|
*/
|
|
237
239
|
getTradingLimitState(exchangeId: string): Promise<TradingLimitsState[]>;
|
|
240
|
+
getAddress(identifier: Identifier): Promise<Address>;
|
|
241
|
+
chainId(): Promise<number>;
|
|
238
242
|
}
|
package/dist/esm/mento.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { BiPoolManager__factory, Broker__factory, IBreakerBox__factory, IBroker__factory, IExchangeProvider__factory, } from '@mento-protocol/mento-core-ts';
|
|
11
11
|
import { Signer } from 'ethers';
|
|
12
12
|
import { getLimits, getLimitsConfig, getLimitsState } from './limits';
|
|
13
|
-
import {
|
|
13
|
+
import { getChainId, getSymbolFromTokenAddress, increaseAllowance, validateSigner, validateSignerOrProvider, } from './utils';
|
|
14
14
|
import { strict as assert } from 'assert';
|
|
15
15
|
import { IMentoRouter__factory } from 'mento-router-ts';
|
|
16
16
|
import { getAddress } from './constants/addresses';
|
|
@@ -25,6 +25,7 @@ export class Mento {
|
|
|
25
25
|
* @param exchanges exchange data for the broker
|
|
26
26
|
*/
|
|
27
27
|
constructor(signerOrProvider, brokerAddress, routerAddress, exchanges) {
|
|
28
|
+
this.cachedChainId = null;
|
|
28
29
|
this.signerOrProvider = signerOrProvider;
|
|
29
30
|
this.broker = IBroker__factory.connect(brokerAddress, signerOrProvider);
|
|
30
31
|
this.router = IMentoRouter__factory.connect(routerAddress, signerOrProvider);
|
|
@@ -39,7 +40,7 @@ export class Mento {
|
|
|
39
40
|
static create(signerOrProvider) {
|
|
40
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
42
|
validateSignerOrProvider(signerOrProvider);
|
|
42
|
-
return new Mento(signerOrProvider, yield
|
|
43
|
+
return new Mento(signerOrProvider, getAddress('Broker', yield getChainId(signerOrProvider)), getAddress('MentoRouter', yield getChainId(signerOrProvider)));
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
/**
|
|
@@ -552,4 +553,17 @@ export class Mento {
|
|
|
552
553
|
return yield Promise.all(configuredLimitCfgs.map((cfg) => __awaiter(this, void 0, void 0, function* () { return yield getLimitsState(broker, exchangeId, cfg.asset); })));
|
|
553
554
|
});
|
|
554
555
|
}
|
|
556
|
+
getAddress(identifier) {
|
|
557
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
558
|
+
return getAddress(identifier, yield this.chainId());
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
chainId() {
|
|
562
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
563
|
+
if (this.cachedChainId == null) {
|
|
564
|
+
this.cachedChainId = yield getChainId(this.signerOrProvider);
|
|
565
|
+
}
|
|
566
|
+
return this.cachedChainId;
|
|
567
|
+
});
|
|
568
|
+
}
|
|
555
569
|
}
|
package/dist/esm/utils.d.ts
CHANGED
|
@@ -19,12 +19,6 @@ export declare function validateSigner(signer: Signer): void;
|
|
|
19
19
|
* @throws if signerOrProvider is invalid or not connected
|
|
20
20
|
*/
|
|
21
21
|
export declare function validateSignerOrProvider(signerOrProvider: Signer | providers.Provider): void;
|
|
22
|
-
/**
|
|
23
|
-
* Returns the broker address from the Celo registry
|
|
24
|
-
* @param signerOrProvider an ethers provider or signer
|
|
25
|
-
* @returns the broker address
|
|
26
|
-
*/
|
|
27
|
-
export declare function getBrokerAddressFromRegistry(signerOrProvider: Signer | providers.Provider): Promise<Address>;
|
|
28
22
|
/**
|
|
29
23
|
* Returns the symbol of an erc20 token
|
|
30
24
|
* @param tokenAddr the address of the erc20 token
|
|
@@ -48,3 +42,4 @@ export declare function increaseAllowance(tokenAddr: string, spender: string, am
|
|
|
48
42
|
* @returns the token address if found, null otherwise
|
|
49
43
|
*/
|
|
50
44
|
export declare function findTokenBySymbol(pairs: readonly TradablePair[], symbol: string): string | null;
|
|
45
|
+
export declare function capitalize(str: string): string;
|
package/dist/esm/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
10
|
+
import { Contract, providers, Signer } from 'ethers';
|
|
11
11
|
/**
|
|
12
12
|
* Gets the chain ID from a signer or provider
|
|
13
13
|
* @param signerOrProvider an ethers provider or signer
|
|
@@ -49,26 +49,6 @@ export function validateSignerOrProvider(signerOrProvider) {
|
|
|
49
49
|
throw new Error('Signer must be connected to a provider');
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Returns the broker address from the Celo registry
|
|
54
|
-
* @param signerOrProvider an ethers provider or signer
|
|
55
|
-
* @returns the broker address
|
|
56
|
-
*/
|
|
57
|
-
export function getBrokerAddressFromRegistry(signerOrProvider) {
|
|
58
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
const celoRegistryAddress = '0x000000000000000000000000000000000000ce10';
|
|
60
|
-
const brokerIdentifier = 'Broker';
|
|
61
|
-
const registryAbi = [
|
|
62
|
-
'function getAddressForString(string calldata identifier) external view returns (address)',
|
|
63
|
-
];
|
|
64
|
-
const contract = new Contract(celoRegistryAddress, registryAbi, signerOrProvider);
|
|
65
|
-
const brokerAddress = yield contract.getAddressForString(brokerIdentifier);
|
|
66
|
-
if (brokerAddress === constants.AddressZero) {
|
|
67
|
-
throw Error('Broker address not found in the registry');
|
|
68
|
-
}
|
|
69
|
-
return brokerAddress;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
52
|
/**
|
|
73
53
|
* Returns the symbol of an erc20 token
|
|
74
54
|
* @param tokenAddr the address of the erc20 token
|
|
@@ -117,3 +97,6 @@ export function findTokenBySymbol(pairs, symbol) {
|
|
|
117
97
|
}
|
|
118
98
|
return null;
|
|
119
99
|
}
|
|
100
|
+
export function capitalize(str) {
|
|
101
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
102
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mento-protocol/mento-sdk",
|
|
3
3
|
"description": "Official SDK for interacting with the Mento Protocol",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.11.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Mento Labs",
|
|
7
7
|
"keywords": [
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
24
|
"analyze": "size-limit --why",
|
|
25
|
-
"build": "yarn build:cjs && yarn build:esm",
|
|
25
|
+
"build": "yarn build:cjs && yarn build:esm && yarn check:scripts",
|
|
26
26
|
"build:cjs": "tsc --project ./tsconfig.json",
|
|
27
27
|
"build:esm": "tsc --project ./tsconfig.esm.json",
|
|
28
28
|
"clean": "rm -rf ./dist",
|
|
29
|
-
"lint": "eslint --config ./.eslintrc.json 'src/**/*.ts' 'scripts/**/*.ts'",
|
|
30
|
-
"
|
|
29
|
+
"lint": "eslint --fix --config ./.eslintrc.json 'src/**/*.ts' 'scripts/**/*.ts'",
|
|
30
|
+
"check:scripts": "tsc --project ./tsconfig.scripts.json",
|
|
31
31
|
"prettier": "prettier --config ./.prettierrc.json --write **/*.{json,md,js,ts,yml}",
|
|
32
32
|
"size": "size-limit",
|
|
33
33
|
"test": "jest --runInBand --verbose",
|
|
@@ -35,8 +35,11 @@
|
|
|
35
35
|
"cacheTradablePairs": "ts-node scripts/cacheTradablePairs.ts",
|
|
36
36
|
"printTradablePairs": "ts-node scripts/printTradablePairs.ts",
|
|
37
37
|
"tradingLimits": "ts-node scripts/printTradingLimits.ts",
|
|
38
|
+
"limits": "yarn tradingLimits",
|
|
38
39
|
"poolConfigs": "ts-node scripts/printPoolConfigs.ts",
|
|
40
|
+
"pools": "ts-node scripts/printPoolConfigs.ts",
|
|
39
41
|
"breakerBox": "ts-node scripts/printBreakerBox.ts",
|
|
42
|
+
"breakers": "yarn breakerBox",
|
|
40
43
|
"quote": "ts-node scripts/quotes/index.ts",
|
|
41
44
|
"getTokenGraph": "ts-node scripts/visualizeTokenGraph.ts"
|
|
42
45
|
},
|
|
@@ -54,6 +57,7 @@
|
|
|
54
57
|
"engines": {
|
|
55
58
|
"node": ">=22"
|
|
56
59
|
},
|
|
60
|
+
"packageManager": "yarn@3",
|
|
57
61
|
"size-limit": [
|
|
58
62
|
{
|
|
59
63
|
"path": "dist/sdk.cjs.production.min.js",
|
|
@@ -91,11 +95,10 @@
|
|
|
91
95
|
"yargs-parser": "^21.1.1"
|
|
92
96
|
},
|
|
93
97
|
"dependencies": {
|
|
94
|
-
"@mento-protocol/mento-core-ts": "
|
|
98
|
+
"@mento-protocol/mento-core-ts": "2.6.5-rc3",
|
|
95
99
|
"mento-router-ts": "^0.2.0"
|
|
96
100
|
},
|
|
97
101
|
"peerDependencies": {
|
|
98
102
|
"ethers": "^5.7"
|
|
99
|
-
}
|
|
100
|
-
"packageManager": "yarn@3.3.1"
|
|
103
|
+
}
|
|
101
104
|
}
|