@mento-protocol/mento-sdk 1.0.0 → 2.0.0-beta.1
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 +124 -8
- package/dist/abis/bipoolmanager.d.ts +15 -0
- package/dist/abis/bipoolmanager.d.ts.map +1 -0
- package/dist/abis/bipoolmanager.js +26 -0
- package/dist/abis/bipoolmanager.js.map +1 -0
- package/dist/abis/broker.d.ts +2 -0
- package/dist/abis/broker.d.ts.map +1 -0
- package/dist/abis/broker.js +8 -0
- package/dist/abis/broker.js.map +1 -0
- package/dist/abis/erc20.d.ts +2 -0
- package/dist/abis/erc20.d.ts.map +1 -0
- package/dist/abis/erc20.js +11 -0
- package/dist/abis/erc20.js.map +1 -0
- package/dist/abis/index.d.ts +4 -0
- package/dist/abis/index.d.ts.map +1 -0
- package/dist/{cjs → abis}/index.js +4 -5
- package/dist/abis/index.js.map +1 -0
- package/dist/abis/pricingmodule.d.ts +2 -0
- package/dist/abis/pricingmodule.d.ts.map +1 -0
- package/dist/abis/pricingmodule.js +5 -0
- package/dist/abis/pricingmodule.js.map +1 -0
- package/dist/abis/reserve.d.ts +2 -0
- package/dist/abis/reserve.d.ts.map +1 -0
- package/dist/abis/reserve.js +9 -0
- package/dist/abis/reserve.js.map +1 -0
- package/dist/adapters/implementations/ethersAdapter.d.ts +10 -0
- package/dist/adapters/implementations/ethersAdapter.d.ts.map +1 -0
- package/dist/adapters/implementations/ethersAdapter.js +22 -0
- package/dist/adapters/implementations/ethersAdapter.js.map +1 -0
- package/dist/adapters/implementations/ethersV5Adapter.d.ts +10 -0
- package/dist/adapters/implementations/ethersV5Adapter.d.ts.map +1 -0
- package/dist/adapters/implementations/ethersV5Adapter.js +22 -0
- package/dist/adapters/implementations/ethersV5Adapter.js.map +1 -0
- package/dist/adapters/implementations/viemAdapter.d.ts +10 -0
- package/dist/adapters/implementations/viemAdapter.d.ts.map +1 -0
- package/dist/adapters/implementations/viemAdapter.js +29 -0
- package/dist/adapters/implementations/viemAdapter.js.map +1 -0
- package/dist/adapters/index.d.ts +5 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +10 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/proxies/ethersAdapterProxy.d.ts +27 -0
- package/dist/adapters/proxies/ethersAdapterProxy.d.ts.map +1 -0
- package/dist/adapters/proxies/ethersAdapterProxy.js +77 -0
- package/dist/adapters/proxies/ethersAdapterProxy.js.map +1 -0
- package/dist/adapters/proxies/ethersV5AdapterProxy.d.ts +27 -0
- package/dist/adapters/proxies/ethersV5AdapterProxy.d.ts.map +1 -0
- package/dist/adapters/proxies/ethersV5AdapterProxy.js +77 -0
- package/dist/adapters/proxies/ethersV5AdapterProxy.js.map +1 -0
- package/dist/adapters/proxies/viemAdapterProxy.d.ts +28 -0
- package/dist/adapters/proxies/viemAdapterProxy.d.ts.map +1 -0
- package/dist/adapters/proxies/viemAdapterProxy.js +77 -0
- package/dist/adapters/proxies/viemAdapterProxy.js.map +1 -0
- package/dist/constants/addresses.d.ts +14 -0
- package/dist/constants/addresses.d.ts.map +1 -0
- package/dist/{cjs/constants → constants}/addresses.js +14 -25
- package/dist/constants/addresses.js.map +1 -0
- package/dist/constants/chainId.d.ts +5 -0
- package/dist/constants/chainId.d.ts.map +1 -0
- package/dist/{cjs/enums → constants}/chainId.js +2 -2
- package/dist/constants/chainId.js.map +1 -0
- package/dist/constants/contractNames.d.ts +21 -0
- package/dist/constants/contractNames.d.ts.map +1 -0
- package/dist/constants/contractNames.js +24 -0
- package/dist/constants/contractNames.js.map +1 -0
- package/dist/constants/index.d.ts +6 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/{cjs/interfaces → constants}/index.js +6 -4
- package/dist/constants/index.js.map +1 -0
- package/dist/{cjs/enums → constants}/proposalState.d.ts +1 -0
- package/dist/constants/proposalState.d.ts.map +1 -0
- package/dist/{cjs/enums → constants}/proposalState.js +2 -1
- package/dist/constants/proposalState.js.map +1 -0
- package/dist/constants/stableTokenMetadata.d.ts +13 -0
- package/dist/constants/stableTokenMetadata.d.ts.map +1 -0
- package/dist/constants/stableTokenMetadata.js +30 -0
- package/dist/constants/stableTokenMetadata.js.map +1 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +122 -0
- package/dist/index.js.map +1 -0
- package/dist/services/collateralAssetService.d.ts +8 -0
- package/dist/services/collateralAssetService.d.ts.map +1 -0
- package/dist/services/collateralAssetService.js +44 -0
- package/dist/services/collateralAssetService.js.map +1 -0
- package/dist/services/exchangeService.d.ts +18 -0
- package/dist/services/exchangeService.d.ts.map +1 -0
- package/dist/services/exchangeService.js +78 -0
- package/dist/services/exchangeService.js.map +1 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/{cjs/enums → services}/index.js +3 -2
- package/dist/services/index.js.map +1 -0
- package/dist/services/stableTokenService.d.ts +8 -0
- package/dist/services/stableTokenService.d.ts.map +1 -0
- package/dist/services/stableTokenService.js +35 -0
- package/dist/services/stableTokenService.js.map +1 -0
- package/dist/services/tokenMetadataService.d.ts +8 -0
- package/dist/services/tokenMetadataService.d.ts.map +1 -0
- package/dist/services/tokenMetadataService.js +45 -0
- package/dist/services/tokenMetadataService.js.map +1 -0
- package/dist/{esm/types → types}/contractAddresses.d.ts +1 -0
- package/dist/types/contractAddresses.d.ts.map +1 -0
- package/dist/{cjs/types → types}/contractAddresses.js +1 -0
- package/dist/types/contractAddresses.js.map +1 -0
- package/dist/types/exchange.d.ts +12 -0
- package/dist/types/exchange.d.ts.map +1 -0
- package/dist/{cjs/interfaces/tradingLimit.js → types/exchange.js} +1 -0
- package/dist/types/exchange.js.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/{cjs/types → types}/index.js +4 -1
- package/dist/types/index.js.map +1 -0
- package/dist/types/provider.d.ts +12 -0
- package/dist/types/provider.d.ts.map +1 -0
- package/dist/{cjs/interfaces/tradingLimitsConfig.js → types/provider.js} +1 -0
- package/dist/types/provider.js.map +1 -0
- package/dist/types/token.d.ts +12 -0
- package/dist/types/token.d.ts.map +1 -0
- package/dist/{cjs/interfaces/IChainClient.js → types/token.js} +1 -0
- package/dist/types/token.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/{cjs/constants → utils}/index.js +2 -1
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/retry.d.ts +12 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +28 -0
- package/dist/utils/retry.js.map +1 -0
- package/package.json +31 -43
- package/dist/cjs/ChainClient.d.ts +0 -9
- package/dist/cjs/ChainClient.js +0 -58
- package/dist/cjs/TestChainClient.d.ts +0 -7
- package/dist/cjs/TestChainClient.js +0 -41
- package/dist/cjs/constants/addresses.d.ts +0 -2
- package/dist/cjs/constants/index.d.ts +0 -1
- package/dist/cjs/enums/chainId.d.ts +0 -5
- package/dist/cjs/enums/index.d.ts +0 -2
- package/dist/cjs/governance.d.ts +0 -62
- package/dist/cjs/governance.js +0 -151
- package/dist/cjs/index.d.ts +0 -5
- package/dist/cjs/interfaces/IChainClient.d.ts +0 -6
- package/dist/cjs/interfaces/index.d.ts +0 -4
- package/dist/cjs/interfaces/tradingLimit.d.ts +0 -7
- package/dist/cjs/interfaces/tradingLimitsConfig.d.ts +0 -10
- package/dist/cjs/interfaces/tradingLimitsState.d.ts +0 -9
- package/dist/cjs/interfaces/tradingLimitsState.js +0 -2
- package/dist/cjs/limits.d.ts +0 -33
- package/dist/cjs/limits.js +0 -130
- package/dist/cjs/mento.d.ts +0 -152
- package/dist/cjs/mento.js +0 -318
- package/dist/cjs/types/contractAddressMap.d.ts +0 -4
- package/dist/cjs/types/contractAddressMap.js +0 -2
- package/dist/cjs/types/contractAddresses.d.ts +0 -22
- package/dist/cjs/types/index.d.ts +0 -2
- package/dist/cjs/utils.d.ts +0 -36
- package/dist/cjs/utils.js +0 -98
- package/dist/esm/ChainClient.d.ts +0 -9
- package/dist/esm/ChainClient.js +0 -54
- package/dist/esm/TestChainClient.d.ts +0 -7
- package/dist/esm/TestChainClient.js +0 -37
- package/dist/esm/constants/addresses.d.ts +0 -2
- package/dist/esm/constants/addresses.js +0 -69
- package/dist/esm/constants/index.d.ts +0 -1
- package/dist/esm/constants/index.js +0 -1
- package/dist/esm/enums/chainId.d.ts +0 -5
- package/dist/esm/enums/chainId.js +0 -6
- package/dist/esm/enums/index.d.ts +0 -2
- package/dist/esm/enums/index.js +0 -2
- package/dist/esm/enums/proposalState.d.ts +0 -10
- package/dist/esm/enums/proposalState.js +0 -11
- package/dist/esm/governance.d.ts +0 -62
- package/dist/esm/governance.js +0 -147
- package/dist/esm/index.d.ts +0 -5
- package/dist/esm/index.js +0 -5
- package/dist/esm/interfaces/IChainClient.d.ts +0 -6
- package/dist/esm/interfaces/IChainClient.js +0 -1
- package/dist/esm/interfaces/index.d.ts +0 -4
- package/dist/esm/interfaces/index.js +0 -4
- package/dist/esm/interfaces/tradingLimit.d.ts +0 -7
- package/dist/esm/interfaces/tradingLimit.js +0 -1
- package/dist/esm/interfaces/tradingLimitsConfig.d.ts +0 -10
- package/dist/esm/interfaces/tradingLimitsConfig.js +0 -1
- package/dist/esm/interfaces/tradingLimitsState.d.ts +0 -9
- package/dist/esm/interfaces/tradingLimitsState.js +0 -1
- package/dist/esm/limits.d.ts +0 -33
- package/dist/esm/limits.js +0 -123
- package/dist/esm/mento.d.ts +0 -152
- package/dist/esm/mento.js +0 -314
- package/dist/esm/types/contractAddressMap.d.ts +0 -4
- package/dist/esm/types/contractAddressMap.js +0 -1
- package/dist/esm/types/contractAddresses.js +0 -1
- package/dist/esm/types/index.d.ts +0 -2
- package/dist/esm/types/index.js +0 -2
- package/dist/esm/utils.d.ts +0 -36
- package/dist/esm/utils.js +0 -90
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.retryOperation = retryOperation;
|
|
4
|
+
/**
|
|
5
|
+
* Retry an operation a number of times with exponential backoff.
|
|
6
|
+
* @param operation - The operation to retry
|
|
7
|
+
* @param options - The retry options
|
|
8
|
+
* @returns The result of the operation
|
|
9
|
+
*/
|
|
10
|
+
async function retryOperation(operation, options = {}) {
|
|
11
|
+
const maxAttempts = options.maxAttempts ?? 3;
|
|
12
|
+
const delayMs = options.initialDelayMs ?? 1000;
|
|
13
|
+
let lastError;
|
|
14
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
15
|
+
try {
|
|
16
|
+
return await operation();
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
lastError = error;
|
|
20
|
+
if (attempt === maxAttempts)
|
|
21
|
+
break;
|
|
22
|
+
// Exponential backoff
|
|
23
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs * attempt));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`Operation failed after ${maxAttempts} attempts: ${lastError?.message}`);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":";;AAWA,wCAuBC;AA7BD;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAClC,SAA2B,EAC3B,UAAwB,EAAE;IAE1B,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,CAAC,CAAA;IAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,IAAI,IAAI,CAAA;IAC9C,IAAI,SAA4B,CAAA;IAEhC,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC;QACxD,IAAI,CAAC;YACH,OAAO,MAAM,SAAS,EAAE,CAAA;QAC1B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,SAAS,GAAG,KAAc,CAAA;YAC1B,IAAI,OAAO,KAAK,WAAW;gBAAE,MAAK;YAElC,sBAAsB;YACtB,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAA;QACxE,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CACb,0BAA0B,WAAW,cAAc,SAAS,EAAE,OAAO,EAAE,CACxE,CAAA;AACH,CAAC"}
|
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": "
|
|
4
|
+
"version": "2.0.0-beta.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Mento Labs",
|
|
7
7
|
"keywords": [
|
|
@@ -13,74 +13,62 @@
|
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "https://github.com/mento-protocol/mento-sdk.git"
|
|
15
15
|
},
|
|
16
|
-
"main": "dist/
|
|
17
|
-
"
|
|
18
|
-
"typings": "dist/esm/index.d.ts",
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
19
18
|
"files": [
|
|
20
19
|
"dist",
|
|
21
20
|
"!dist/**/*.test.*"
|
|
22
21
|
],
|
|
22
|
+
"type": "commonjs",
|
|
23
23
|
"scripts": {
|
|
24
|
-
"
|
|
25
|
-
"build": "yarn build:cjs && yarn build:esm",
|
|
26
|
-
"build:cjs": "tsc --project ./tsconfig.json",
|
|
27
|
-
"build:esm": "tsc --project ./tsconfig.esm.json",
|
|
24
|
+
"build": "pnpm clean && tsc --project ./tsconfig.json",
|
|
28
25
|
"clean": "rm -rf ./dist",
|
|
29
26
|
"lint": "eslint --config ./.eslintrc.json src/**/*.ts",
|
|
30
27
|
"prettier": "prettier --config ./.prettierrc.json --write **/*.{json,md,js,ts,yml}",
|
|
31
|
-
"
|
|
32
|
-
"test": "jest --runInBand --verbose",
|
|
28
|
+
"test": "jest --verbose",
|
|
33
29
|
"coverage": "jest --coverage"
|
|
34
30
|
},
|
|
35
|
-
"husky": {
|
|
36
|
-
"hooks": {
|
|
37
|
-
"pre-commit": "yarn lint"
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
"jest": {
|
|
41
|
-
"testEnvironment": "node",
|
|
42
|
-
"testMatch": [
|
|
43
|
-
"**/?(*.)+(test).ts"
|
|
44
|
-
]
|
|
45
|
-
},
|
|
46
31
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
32
|
+
"node": ">=18",
|
|
33
|
+
"pnpm": ">=9"
|
|
48
34
|
},
|
|
49
|
-
"size-limit": [
|
|
50
|
-
{
|
|
51
|
-
"path": "dist/sdk.cjs.production.min.js",
|
|
52
|
-
"limit": "10 KB"
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"path": "dist/sdk.esm.js",
|
|
56
|
-
"limit": "10 KB"
|
|
57
|
-
}
|
|
58
|
-
],
|
|
59
35
|
"devDependencies": {
|
|
60
|
-
"@
|
|
61
|
-
"@babel/preset-typescript": "^7.18.6",
|
|
36
|
+
"@jest/types": "^29.6.3",
|
|
62
37
|
"@size-limit/preset-small-lib": "^8.1.0",
|
|
63
38
|
"@tsconfig/recommended": "^1.0.1",
|
|
64
|
-
"@types/
|
|
39
|
+
"@types/chai": "^5.0.1",
|
|
40
|
+
"@types/jest": "^29.5.14",
|
|
65
41
|
"@types/node": "^18.13.0",
|
|
66
42
|
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
67
43
|
"@typescript-eslint/parser": "^5.53.0",
|
|
44
|
+
"chai": "^5.1.2",
|
|
68
45
|
"eslint": "^8.34.0",
|
|
69
46
|
"eslint-config-prettier": "^8.6.0",
|
|
70
|
-
"ethers": "^5.7.2",
|
|
71
47
|
"husky": "^8.0.2",
|
|
72
48
|
"jest": "^29.4.2",
|
|
73
49
|
"prettier": "^2.8.4",
|
|
74
|
-
"size-limit": "^8.1.0",
|
|
75
50
|
"ts-jest": "^29.0.5",
|
|
76
51
|
"ts-node": "^10.9.1",
|
|
77
|
-
"typescript": "
|
|
78
|
-
},
|
|
79
|
-
"dependencies": {
|
|
80
|
-
"@mento-protocol/mento-core-ts": "^0.2.0"
|
|
52
|
+
"typescript": "5.6.3"
|
|
81
53
|
},
|
|
82
54
|
"peerDependencies": {
|
|
83
|
-
"ethers": "^
|
|
55
|
+
"ethers": "^6.13.4",
|
|
56
|
+
"ethers-v5": "npm:ethers@^5.7.2",
|
|
57
|
+
"viem": "^2.21.44"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"ethers": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"ethers-v5": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"viem": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
84
69
|
},
|
|
85
|
-
"
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"@mento-protocol/mento-core-ts": "^0.2.0",
|
|
72
|
+
"bignumber.js": "^9.1.2"
|
|
73
|
+
}
|
|
86
74
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { PopulatedTransaction, ethers, providers } from 'ethers';
|
|
2
|
-
import { IChainClient } from './interfaces';
|
|
3
|
-
export declare class ChainClient implements IChainClient {
|
|
4
|
-
private readonly signerOrProvider;
|
|
5
|
-
constructor(signerOrProvider: ethers.Signer | providers.Provider);
|
|
6
|
-
getSigner(): Promise<ethers.Signer | providers.Provider>;
|
|
7
|
-
getChainId(): Promise<number>;
|
|
8
|
-
populateTransaction(tx: PopulatedTransaction): Promise<providers.TransactionRequest>;
|
|
9
|
-
}
|
package/dist/cjs/ChainClient.js
DELETED
|
@@ -1,58 +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.ChainClient = void 0;
|
|
13
|
-
const ethers_1 = require("ethers");
|
|
14
|
-
const utils_1 = require("./utils");
|
|
15
|
-
class ChainClient {
|
|
16
|
-
constructor(signerOrProvider) {
|
|
17
|
-
(0, utils_1.validateSignerOrProvider)(signerOrProvider);
|
|
18
|
-
this.signerOrProvider = signerOrProvider;
|
|
19
|
-
}
|
|
20
|
-
getSigner() {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
return this.signerOrProvider;
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
getChainId() {
|
|
26
|
-
var _a;
|
|
27
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
let chainId = 0;
|
|
29
|
-
if (ethers_1.Signer.isSigner(this.signerOrProvider)) {
|
|
30
|
-
const network = yield ((_a = this.signerOrProvider.provider) === null || _a === void 0 ? void 0 : _a.getNetwork());
|
|
31
|
-
if (network) {
|
|
32
|
-
chainId = network.chainId;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else if (ethers_1.providers.Provider.isProvider(this.signerOrProvider)) {
|
|
36
|
-
const network = yield this.signerOrProvider.getNetwork();
|
|
37
|
-
if (network) {
|
|
38
|
-
chainId = network.chainId;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (chainId === 0) {
|
|
42
|
-
throw new Error('Could not get chainId from signer or provider');
|
|
43
|
-
}
|
|
44
|
-
return chainId;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
populateTransaction(tx) {
|
|
48
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
if (ethers_1.Signer.isSigner(this.signerOrProvider)) {
|
|
50
|
-
return this.signerOrProvider.populateTransaction(tx);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
return tx;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.ChainClient = ChainClient;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { PopulatedTransaction, ethers, providers } from 'ethers';
|
|
2
|
-
import { IChainClient } from './interfaces';
|
|
3
|
-
export declare class TestChainClient implements IChainClient {
|
|
4
|
-
getSigner(): Promise<ethers.Signer | providers.Provider>;
|
|
5
|
-
getChainId(): Promise<number>;
|
|
6
|
-
populateTransaction(tx: PopulatedTransaction): Promise<providers.TransactionRequest>;
|
|
7
|
-
}
|
|
@@ -1,41 +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.TestChainClient = void 0;
|
|
13
|
-
class TestChainClient {
|
|
14
|
-
getSigner() {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const fakeProvider = {};
|
|
17
|
-
return fakeProvider;
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
getChainId() {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
return 44787;
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
populateTransaction(tx) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const fakeTx = {
|
|
28
|
-
to: tx.to,
|
|
29
|
-
from: tx.from,
|
|
30
|
-
data: tx.data,
|
|
31
|
-
value: tx.value,
|
|
32
|
-
nonce: 0,
|
|
33
|
-
gasLimit: 0,
|
|
34
|
-
gasPrice: 0,
|
|
35
|
-
chainId: 1,
|
|
36
|
-
};
|
|
37
|
-
return fakeTx;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.TestChainClient = TestChainClient;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './addresses';
|
package/dist/cjs/governance.d.ts
DELETED
|
@@ -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
|
-
}
|
package/dist/cjs/governance.js
DELETED
|
@@ -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;
|
package/dist/cjs/index.d.ts
DELETED
package/dist/cjs/limits.d.ts
DELETED
|
@@ -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;
|