@mento-protocol/mento-sdk 0.1.4 → 0.2.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 +9 -65
- package/dist/cjs/ChainClient.d.ts +9 -0
- package/dist/cjs/ChainClient.js +58 -0
- package/dist/cjs/TestChainClient.d.ts +7 -0
- package/dist/cjs/TestChainClient.js +41 -0
- package/dist/cjs/contracts.json +26 -0
- package/dist/cjs/governance.d.ts +62 -0
- package/dist/cjs/governance.js +147 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/limits.d.ts +33 -0
- package/dist/cjs/limits.js +122 -0
- package/dist/cjs/mento.d.ts +39 -4
- package/dist/cjs/mento.js +81 -2
- package/dist/cjs/types.d.ts +48 -0
- package/dist/cjs/types.js +12 -0
- package/dist/cjs/utils.d.ts +2 -1
- package/dist/cjs/utils.js +14 -1
- package/dist/esm/ChainClient.d.ts +9 -0
- package/dist/esm/ChainClient.js +54 -0
- package/dist/esm/TestChainClient.d.ts +7 -0
- package/dist/esm/TestChainClient.js +37 -0
- package/dist/esm/contracts.json +26 -0
- package/dist/esm/governance.d.ts +62 -0
- package/dist/esm/governance.js +143 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/limits.d.ts +33 -0
- package/dist/esm/limits.js +115 -0
- package/dist/esm/mento.d.ts +39 -4
- package/dist/esm/mento.js +82 -3
- package/dist/esm/types.d.ts +48 -0
- package/dist/esm/types.js +11 -1
- package/dist/esm/utils.d.ts +2 -1
- package/dist/esm/utils.js +9 -0
- package/package.json +2 -2
package/dist/cjs/mento.js
CHANGED
|
@@ -13,6 +13,7 @@ exports.Mento = void 0;
|
|
|
13
13
|
const mento_core_ts_1 = require("@mento-protocol/mento-core-ts");
|
|
14
14
|
const ethers_1 = require("ethers");
|
|
15
15
|
const utils_1 = require("./utils");
|
|
16
|
+
const limits_1 = require("./limits");
|
|
16
17
|
const assert_1 = require("assert");
|
|
17
18
|
class Mento {
|
|
18
19
|
/**
|
|
@@ -214,8 +215,8 @@ class Mento {
|
|
|
214
215
|
}
|
|
215
216
|
/**
|
|
216
217
|
* Returns the Mento exchange (if any) for a given pair of tokens
|
|
217
|
-
* @param token0 the first token
|
|
218
|
-
* @param token1 the second token
|
|
218
|
+
* @param token0 the address of the first token
|
|
219
|
+
* @param token1 the address of the second token
|
|
219
220
|
* @returns exchange
|
|
220
221
|
*/
|
|
221
222
|
getExchangeForTokens(token0, token1) {
|
|
@@ -228,5 +229,83 @@ class Mento {
|
|
|
228
229
|
return exchanges[0];
|
|
229
230
|
});
|
|
230
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Returns the Mento exchange for a given exchange id
|
|
234
|
+
* @param exchangeId the id of the exchange
|
|
235
|
+
* @returns the exchange with the given id
|
|
236
|
+
*/
|
|
237
|
+
getExchangeById(exchangeId) {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
const exchanges = (yield this.getExchanges()).filter((e) => e.id === exchangeId);
|
|
240
|
+
if (exchanges.length === 0) {
|
|
241
|
+
throw Error(`No exchange found for id ${exchangeId}`);
|
|
242
|
+
}
|
|
243
|
+
(0, assert_1.strict)(exchanges.length === 1, `More than one exchange found with id ${exchangeId}`);
|
|
244
|
+
return exchanges[0];
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Returns whether trading is enabled in the given mode for a given exchange id
|
|
249
|
+
* @param exchangeId the id of the exchange
|
|
250
|
+
* @param mode the trading mode
|
|
251
|
+
* @returns true if trading is enabled in the given mode, false otherwise
|
|
252
|
+
*/
|
|
253
|
+
isTradingEnabled(exchangeId) {
|
|
254
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
255
|
+
const exchange = yield this.getExchangeById(exchangeId);
|
|
256
|
+
const biPoolManager = mento_core_ts_1.BiPoolManager__factory.connect(exchange.providerAddr, this.signerOrProvider);
|
|
257
|
+
const [breakerBoxAddr, exchangeConfig] = yield Promise.all([
|
|
258
|
+
biPoolManager.breakerBox(),
|
|
259
|
+
biPoolManager.getPoolExchange(exchangeId),
|
|
260
|
+
]);
|
|
261
|
+
const breakerBox = mento_core_ts_1.IBreakerBox__factory.connect(breakerBoxAddr, this.signerOrProvider);
|
|
262
|
+
const currentMode = yield breakerBox.getRateFeedTradingMode(exchangeConfig.config.referenceRateFeedID);
|
|
263
|
+
const BI_DIRECTIONAL_TRADING_MODE = 0;
|
|
264
|
+
return currentMode == BI_DIRECTIONAL_TRADING_MODE;
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Return the trading limits for a given exchange id. Each limit is an object with the following fields:
|
|
269
|
+
* asset: the address of the asset with the limit
|
|
270
|
+
* maxIn: the maximum amount of the asset that can be sold
|
|
271
|
+
* maxOut: the maximum amount of the asset that can be bought
|
|
272
|
+
* until: the timestamp until which the limit is valid
|
|
273
|
+
* @param exchangeId the id of the exchange
|
|
274
|
+
* @returns the list of trading limits
|
|
275
|
+
*/
|
|
276
|
+
getTradingLimits(exchangeId) {
|
|
277
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
278
|
+
const exchange = yield this.getExchangeById(exchangeId);
|
|
279
|
+
const broker = mento_core_ts_1.Broker__factory.connect(this.broker.address, this.signerOrProvider);
|
|
280
|
+
const assetWithLimit = exchange.assets[0]; // currently limits are configured only on asset0
|
|
281
|
+
return (0, limits_1.getLimits)(broker, exchangeId, assetWithLimit);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Returns the trading limits configuration for a given exchange id
|
|
286
|
+
* @param exchangeId the id of the exchange
|
|
287
|
+
* @returns the trading limits configuration
|
|
288
|
+
*/
|
|
289
|
+
getTradingLimitConfig(exchangeId) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
const exchange = yield this.getExchangeById(exchangeId);
|
|
292
|
+
const broker = mento_core_ts_1.Broker__factory.connect(this.broker.address, this.signerOrProvider);
|
|
293
|
+
const assetWithLimit = exchange.assets[0]; // currently limits are configured only on asset0
|
|
294
|
+
return (0, limits_1.getLimitsConfig)(broker, exchangeId, assetWithLimit);
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Returns the trading limits state for a given exchange id
|
|
299
|
+
* @param exchangeId the id of the exchange
|
|
300
|
+
* @returns the trading limits state
|
|
301
|
+
*/
|
|
302
|
+
getTradingLimitState(exchangeId) {
|
|
303
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
304
|
+
const exchange = yield this.getExchangeById(exchangeId);
|
|
305
|
+
const broker = mento_core_ts_1.Broker__factory.connect(this.broker.address, this.signerOrProvider);
|
|
306
|
+
const assetWithLimit = exchange.assets[0]; // currently limits are configured only on asset0
|
|
307
|
+
return (0, limits_1.getLimitsState)(broker, exchangeId, assetWithLimit);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
231
310
|
}
|
|
232
311
|
exports.Mento = Mento;
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1 +1,49 @@
|
|
|
1
|
+
import { ethers, providers } from "ethers";
|
|
1
2
|
export type Address = string;
|
|
3
|
+
export interface TradingLimit {
|
|
4
|
+
asset: Address;
|
|
5
|
+
maxIn: number;
|
|
6
|
+
maxOut: number;
|
|
7
|
+
until: number;
|
|
8
|
+
}
|
|
9
|
+
export interface TradingLimitsConfig {
|
|
10
|
+
timestep0: number;
|
|
11
|
+
timestep1: number;
|
|
12
|
+
limit0: number;
|
|
13
|
+
limit1: number;
|
|
14
|
+
limitGlobal: number;
|
|
15
|
+
flags: number;
|
|
16
|
+
}
|
|
17
|
+
export interface TradingLimitsState {
|
|
18
|
+
lastUpdated0: number;
|
|
19
|
+
lastUpdated1: number;
|
|
20
|
+
netflow0: number;
|
|
21
|
+
netflow1: number;
|
|
22
|
+
netflowGlobal: number;
|
|
23
|
+
}
|
|
24
|
+
export interface ContractAddressMap {
|
|
25
|
+
[chainId: string]: ContractAddresses;
|
|
26
|
+
}
|
|
27
|
+
export interface ContractAddresses {
|
|
28
|
+
Airgrab: string;
|
|
29
|
+
Emission: string;
|
|
30
|
+
MentoGovernor: string;
|
|
31
|
+
MentoToken: string;
|
|
32
|
+
TimelockController: string;
|
|
33
|
+
Locking: string;
|
|
34
|
+
}
|
|
35
|
+
export declare enum ProposalState {
|
|
36
|
+
PENDING = 0,
|
|
37
|
+
ACTIVE = 1,
|
|
38
|
+
CANCELED = 2,
|
|
39
|
+
DEFEATED = 3,
|
|
40
|
+
SUCCEEDED = 4,
|
|
41
|
+
QUEUED = 5,
|
|
42
|
+
EXPIRED = 6,
|
|
43
|
+
EXECUTED = 7
|
|
44
|
+
}
|
|
45
|
+
export interface IChainClient {
|
|
46
|
+
getSigner(): Promise<ethers.Signer | providers.Provider>;
|
|
47
|
+
getChainId(): Promise<number>;
|
|
48
|
+
populateTransaction(tx: ethers.PopulatedTransaction): Promise<providers.TransactionRequest>;
|
|
49
|
+
}
|
package/dist/cjs/types.js
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProposalState = void 0;
|
|
4
|
+
var ProposalState;
|
|
5
|
+
(function (ProposalState) {
|
|
6
|
+
ProposalState[ProposalState["PENDING"] = 0] = "PENDING";
|
|
7
|
+
ProposalState[ProposalState["ACTIVE"] = 1] = "ACTIVE";
|
|
8
|
+
ProposalState[ProposalState["CANCELED"] = 2] = "CANCELED";
|
|
9
|
+
ProposalState[ProposalState["DEFEATED"] = 3] = "DEFEATED";
|
|
10
|
+
ProposalState[ProposalState["SUCCEEDED"] = 4] = "SUCCEEDED";
|
|
11
|
+
ProposalState[ProposalState["QUEUED"] = 5] = "QUEUED";
|
|
12
|
+
ProposalState[ProposalState["EXPIRED"] = 6] = "EXPIRED";
|
|
13
|
+
ProposalState[ProposalState["EXECUTED"] = 7] = "EXECUTED";
|
|
14
|
+
})(ProposalState = exports.ProposalState || (exports.ProposalState = {}));
|
package/dist/cjs/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BigNumberish, providers, Signer } from 'ethers';
|
|
2
|
-
import { Address } from './types';
|
|
2
|
+
import { Address, ContractAddresses } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Ensures that given signer is truly a a connected signer
|
|
5
5
|
* @param signer an ethers signer
|
|
@@ -34,3 +34,4 @@ export declare function getSymbolFromTokenAddress(tokenAddr: Address, signerOrPr
|
|
|
34
34
|
* @returns the populated TransactionRequest object
|
|
35
35
|
*/
|
|
36
36
|
export declare function increaseAllowance(tokenAddr: string, spender: string, amount: BigNumberish, signerOrProvider: Signer | providers.Provider): Promise<providers.TransactionRequest>;
|
|
37
|
+
export declare function getContractsByChainId(chainId: number): ContractAddresses;
|
package/dist/cjs/utils.js
CHANGED
|
@@ -8,9 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.increaseAllowance = exports.getSymbolFromTokenAddress = exports.getBrokerAddressFromRegistry = exports.validateSignerOrProvider = exports.validateSigner = void 0;
|
|
15
|
+
exports.getContractsByChainId = exports.increaseAllowance = exports.getSymbolFromTokenAddress = exports.getBrokerAddressFromRegistry = exports.validateSignerOrProvider = exports.validateSigner = void 0;
|
|
13
16
|
const ethers_1 = require("ethers");
|
|
17
|
+
const contracts_json_1 = __importDefault(require("./contracts.json"));
|
|
14
18
|
/**
|
|
15
19
|
* Ensures that given signer is truly a a connected signer
|
|
16
20
|
* @param signer an ethers signer
|
|
@@ -96,3 +100,12 @@ function increaseAllowance(tokenAddr, spender, amount, signerOrProvider) {
|
|
|
96
100
|
});
|
|
97
101
|
}
|
|
98
102
|
exports.increaseAllowance = increaseAllowance;
|
|
103
|
+
function getContractsByChainId(chainId) {
|
|
104
|
+
const addresses = contracts_json_1.default;
|
|
105
|
+
const contracts = addresses[chainId];
|
|
106
|
+
if (!contracts) {
|
|
107
|
+
throw new Error(`No contracts found for chainId ${chainId}`);
|
|
108
|
+
}
|
|
109
|
+
return contracts;
|
|
110
|
+
}
|
|
111
|
+
exports.getContractsByChainId = getContractsByChainId;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PopulatedTransaction, ethers, providers } from "ethers";
|
|
2
|
+
import { IChainClient } from "./types";
|
|
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
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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 { Signer, providers } from "ethers";
|
|
11
|
+
import { validateSignerOrProvider } from "./utils";
|
|
12
|
+
export class ChainClient {
|
|
13
|
+
constructor(signerOrProvider) {
|
|
14
|
+
validateSignerOrProvider(signerOrProvider);
|
|
15
|
+
this.signerOrProvider = signerOrProvider;
|
|
16
|
+
}
|
|
17
|
+
getSigner() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
return this.signerOrProvider;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
getChainId() {
|
|
23
|
+
var _a;
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
let chainId = 0;
|
|
26
|
+
if (Signer.isSigner(this.signerOrProvider)) {
|
|
27
|
+
const network = yield ((_a = this.signerOrProvider.provider) === null || _a === void 0 ? void 0 : _a.getNetwork());
|
|
28
|
+
if (network) {
|
|
29
|
+
chainId = network.chainId;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (providers.Provider.isProvider(this.signerOrProvider)) {
|
|
33
|
+
const network = yield this.signerOrProvider.getNetwork();
|
|
34
|
+
if (network) {
|
|
35
|
+
chainId = network.chainId;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (chainId === 0) {
|
|
39
|
+
throw new Error('Could not get chainId from signer or provider');
|
|
40
|
+
}
|
|
41
|
+
return chainId;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
populateTransaction(tx) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
if (Signer.isSigner(this.signerOrProvider)) {
|
|
47
|
+
return this.signerOrProvider.populateTransaction(tx);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return tx;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PopulatedTransaction, ethers, providers } from 'ethers';
|
|
2
|
+
import { IChainClient } from './types';
|
|
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
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
export class TestChainClient {
|
|
11
|
+
getSigner() {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
const fakeProvider = {};
|
|
14
|
+
return fakeProvider;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
getChainId() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
return 1;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
populateTransaction(tx) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const fakeTx = {
|
|
25
|
+
to: tx.to,
|
|
26
|
+
from: tx.from,
|
|
27
|
+
data: tx.data,
|
|
28
|
+
value: tx.value,
|
|
29
|
+
nonce: 0,
|
|
30
|
+
gasLimit: 0,
|
|
31
|
+
gasPrice: 0,
|
|
32
|
+
chainId: 1,
|
|
33
|
+
};
|
|
34
|
+
return fakeTx;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"42220": {
|
|
3
|
+
"Airgrab": "",
|
|
4
|
+
"Emission": "",
|
|
5
|
+
"MentoGovernor": "",
|
|
6
|
+
"MentoToken": "",
|
|
7
|
+
"TimelockController": "",
|
|
8
|
+
"Locking": ""
|
|
9
|
+
},
|
|
10
|
+
"62320": {
|
|
11
|
+
"Airgrab": "0x349aa8910577A6fE16cA7b98b5A135d14CE4dF9f",
|
|
12
|
+
"Emission": "0xcd427DDB27D835E5353312e7897bb9ad35F0E214",
|
|
13
|
+
"MentoGovernor": "0x5dFE8CC7743C636a86bED8F8d0de982d502E22fC",
|
|
14
|
+
"MentoToken": "0xD2f4f160BAF7D88a7A9189b03D0B3AA6A5D9775B",
|
|
15
|
+
"TimelockController": "0xb5977b1d208ef35FAf97A9534Dd849c356F362C5",
|
|
16
|
+
"Locking": "0x831DAfC0912e1c2aBa2Da90668c0856d48a8C06b"
|
|
17
|
+
},
|
|
18
|
+
"44787": {
|
|
19
|
+
"Airgrab": "0x281fA47f59456fA04DF699539fA4b1F25e7769A3",
|
|
20
|
+
"Emission": "0x8D1267bFf3f8166AEB2B58217b74188d1fe326f3",
|
|
21
|
+
"MentoGovernor": "0x84382a356c1Dc6ada21997E64dc72e5a7AcF5826",
|
|
22
|
+
"MentoToken": "0x53De3F938c64baB8C621c8A3C5000b385afE2404",
|
|
23
|
+
"TimelockController": "0x2AFC4a1e7928Fb3bfC81076740d3142FF8B1DE05",
|
|
24
|
+
"Locking": "0x65a1271ce7B2ec8D564A4Bc752E13A36a46e81B8"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { BigNumberish, Signer, providers } from 'ethers';
|
|
2
|
+
import { MentoGovernor } from '@mento-protocol/mento-core-ts';
|
|
3
|
+
import { IChainClient } from './types';
|
|
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
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
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 { Signer, providers } from 'ethers';
|
|
11
|
+
import { getContractsByChainId } from './utils';
|
|
12
|
+
import { MentoGovernor__factory, } from '@mento-protocol/mento-core-ts';
|
|
13
|
+
import { ProposalState } from './types';
|
|
14
|
+
import { ChainClient } from './ChainClient';
|
|
15
|
+
import { TestChainClient } from './TestChainClient';
|
|
16
|
+
export class Governance {
|
|
17
|
+
constructor(arg) {
|
|
18
|
+
// TODO: Remove use of TestChainClient in future this is only meant for testing
|
|
19
|
+
if (arg instanceof ChainClient || arg instanceof TestChainClient) {
|
|
20
|
+
this.chainClient = arg;
|
|
21
|
+
}
|
|
22
|
+
else if (Signer.isSigner(arg) || providers.Provider.isProvider(arg)) {
|
|
23
|
+
this.chainClient = new ChainClient(arg);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw new Error('Invalid constructor argument');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* This function retrieves the MentoGovernor contract.
|
|
31
|
+
* @returns The MentoGovernor contract.
|
|
32
|
+
*/
|
|
33
|
+
getGovernorContract() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const contracts = getContractsByChainId(yield this.chainClient.getChainId());
|
|
36
|
+
const mentoGovernorAddress = contracts.MentoGovernor;
|
|
37
|
+
return MentoGovernor__factory.connect(mentoGovernorAddress, yield this.chainClient.getSigner());
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Generates a transaction that submits a proposal to be created to the Mento Governor contract using the specified values.
|
|
42
|
+
* @param targets The addresses of the contracts to be called during proposal execution.
|
|
43
|
+
* @param values The values to be passed to the calls to the target contracts.
|
|
44
|
+
* @param calldatas The calldata to be passed to the calls to the target contracts.
|
|
45
|
+
* @param description A human readable description of the proposal.
|
|
46
|
+
* @returns The transaction request.
|
|
47
|
+
*/
|
|
48
|
+
createProposal(targets, values, calldatas, description) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
this.validateProposalArgs(targets, values, calldatas, description);
|
|
51
|
+
const governor = yield this.getGovernorContract();
|
|
52
|
+
const tx = yield governor.populateTransaction['propose(address[],uint256[],bytes[],string)'](targets, values, calldatas, description);
|
|
53
|
+
return yield this.chainClient.populateTransaction(tx);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Generates a transaction that will queue the proposal with the specified id to be executed.
|
|
58
|
+
* @param proposalId The id of the proposal to queue.
|
|
59
|
+
* @returns The transaction request.
|
|
60
|
+
*/
|
|
61
|
+
queueProposal(proposalId) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const governor = yield this.getGovernorContract();
|
|
64
|
+
const tx = yield governor.populateTransaction['queue(uint256)'](proposalId);
|
|
65
|
+
return yield this.chainClient.populateTransaction(tx);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Executes the proposal with the specified id.
|
|
70
|
+
* @param proposalId The id of the proposal to execute.
|
|
71
|
+
* @returns The transaction request.
|
|
72
|
+
*/
|
|
73
|
+
executeProposal(proposalId) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const governor = yield this.getGovernorContract();
|
|
76
|
+
const tx = yield governor.populateTransaction['execute(uint256)'](proposalId);
|
|
77
|
+
return yield this.chainClient.populateTransaction(tx);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Submits a vote to the Mento Governor contract for the specified proposal.
|
|
82
|
+
* @param proposalId The id of the proposal to vote on.
|
|
83
|
+
* @param support Whether or not to support the proposal.
|
|
84
|
+
* @returns The transaction request.
|
|
85
|
+
*/
|
|
86
|
+
castVote(proposalId, support) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
const governor = yield this.getGovernorContract();
|
|
89
|
+
const tx = yield governor.populateTransaction.castVote(proposalId, support);
|
|
90
|
+
return yield this.chainClient.populateTransaction(tx);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Cancels the proposal with the specified id.
|
|
95
|
+
* @param proposalId The id of the proposal to vote on.
|
|
96
|
+
* @param support Whether or not to support the proposal.
|
|
97
|
+
* @returns The transaction request.
|
|
98
|
+
*/
|
|
99
|
+
cancelProposal(proposalId) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
const governor = yield this.getGovernorContract();
|
|
102
|
+
const tx = yield governor.populateTransaction.cancel(proposalId);
|
|
103
|
+
return yield this.chainClient.populateTransaction(tx);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Returns the state of the proposal with the specified id.
|
|
108
|
+
* @param proposalId The id of the proposal to get the state of.
|
|
109
|
+
* @returns The state of the proposal.
|
|
110
|
+
*/
|
|
111
|
+
getProposalState(proposalId) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const governor = yield this.getGovernorContract();
|
|
114
|
+
const state = (yield governor.functions.state(proposalId))[0];
|
|
115
|
+
return ProposalState[state];
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* This function validates the args that are to be used in the createProposal function.
|
|
120
|
+
* @param targets The addresses of the contracts to be called during proposal execution.
|
|
121
|
+
* @param values The values to be passed to the calls to the target contracts.
|
|
122
|
+
* @param calldatas The calldata to be passed to the calls to the target contracts.
|
|
123
|
+
* @param description A human readable description of the proposal.
|
|
124
|
+
*/
|
|
125
|
+
validateProposalArgs(targets, values, calldatas, description) {
|
|
126
|
+
if (!targets || targets.length === 0) {
|
|
127
|
+
throw new Error('Targets must be specified');
|
|
128
|
+
}
|
|
129
|
+
if (!values || values.length === 0) {
|
|
130
|
+
throw new Error('Values must be specified');
|
|
131
|
+
}
|
|
132
|
+
if (!calldatas || calldatas.length === 0) {
|
|
133
|
+
throw new Error('Calldatas must be specified');
|
|
134
|
+
}
|
|
135
|
+
if (!description) {
|
|
136
|
+
throw new Error('Description must be specified');
|
|
137
|
+
}
|
|
138
|
+
if (targets.length !== values.length ||
|
|
139
|
+
targets.length !== calldatas.length) {
|
|
140
|
+
throw new Error('Targets, values, and calldatas must all have the same length');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Address, TradingLimit, TradingLimitsConfig, TradingLimitsState } from './types';
|
|
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;
|