@mento-protocol/mento-sdk 0.1.5 → 0.2.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 CHANGED
@@ -14,4 +14,4 @@ yarn add @mento-protocol/mento-sdk
14
14
 
15
15
  # Learn more
16
16
 
17
- You can find example usages of the SDK in the [mento-sdk-examples](https://github.com/mento-protocol/mento-sdk-examples) repository. For in-depth documentation and walk through explanations please see the [SDK section](https://docs.mento.org/mento-protocol/developers/sdk) of the Mento docs.
17
+ You can find example usages of the SDK in the [mento-sdk-examples](https://github.com/mento-protocol/mento-sdk-examples) repository. For in-depth documentation and walk through explanations please see the [SDK section](https://docs.mento.org/mento/developers/mento-sdk) of the Mento docs.
@@ -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,58 @@
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;
@@ -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,41 @@
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 1;
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;
@@ -0,0 +1,29 @@
1
+ {
2
+ "42220": {
3
+ "GovernanceFactory": "",
4
+ "Airgrab": "",
5
+ "Emission": "",
6
+ "MentoGovernor": "",
7
+ "MentoToken": "",
8
+ "TimelockController": "",
9
+ "Locking": ""
10
+ },
11
+ "62320": {
12
+ "GovernanceFactory": "0x77645271665AdDF195202dEf1ad3cA678B442411",
13
+ "Airgrab": "0x349aa8910577A6fE16cA7b98b5A135d14CE4dF9f",
14
+ "Emission": "0xcd427DDB27D835E5353312e7897bb9ad35F0E214",
15
+ "MentoGovernor": "0x5dFE8CC7743C636a86bED8F8d0de982d502E22fC",
16
+ "MentoToken": "0xD2f4f160BAF7D88a7A9189b03D0B3AA6A5D9775B",
17
+ "TimelockController": "0xb5977b1d208ef35FAf97A9534Dd849c356F362C5",
18
+ "Locking": "0x831DAfC0912e1c2aBa2Da90668c0856d48a8C06b"
19
+ },
20
+ "44787": {
21
+ "GovernanceFactory": "0xD4079B322c392D6b196f90AA4c439fC2C16d6770",
22
+ "Airgrab": "0x281fA47f59456fA04DF699539fA4b1F25e7769A3",
23
+ "Emission": "0x8D1267bFf3f8166AEB2B58217b74188d1fe326f3",
24
+ "MentoGovernor": "0x84382a356c1Dc6ada21997E64dc72e5a7AcF5826",
25
+ "MentoToken": "0x53De3F938c64baB8C621c8A3C5000b385afE2404",
26
+ "TimelockController": "0x2AFC4a1e7928Fb3bfC81076740d3142FF8B1DE05",
27
+ "Locking": "0x65a1271ce7B2ec8D564A4Bc752E13A36a46e81B8"
28
+ }
29
+ }
@@ -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,147 @@
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 utils_1 = require("./utils");
15
+ const mento_core_ts_1 = require("@mento-protocol/mento-core-ts");
16
+ const types_1 = require("./types");
17
+ const ChainClient_1 = require("./ChainClient");
18
+ const TestChainClient_1 = require("./TestChainClient");
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 contracts = (0, utils_1.getContractsByChainId)(yield this.chainClient.getChainId());
39
+ const mentoGovernorAddress = contracts.MentoGovernor;
40
+ return mento_core_ts_1.MentoGovernor__factory.connect(mentoGovernorAddress, yield this.chainClient.getSigner());
41
+ });
42
+ }
43
+ /**
44
+ * Generates a transaction that submits a proposal to be created to the Mento Governor contract using the specified values.
45
+ * @param targets The addresses of the contracts to be called during proposal execution.
46
+ * @param values The values to be passed to the calls to the target contracts.
47
+ * @param calldatas The calldata to be passed to the calls to the target contracts.
48
+ * @param description A human readable description of the proposal.
49
+ * @returns The transaction request.
50
+ */
51
+ createProposal(targets, values, calldatas, description) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ this.validateProposalArgs(targets, values, calldatas, description);
54
+ const governor = yield this.getGovernorContract();
55
+ const tx = yield governor.populateTransaction['propose(address[],uint256[],bytes[],string)'](targets, values, calldatas, description);
56
+ return yield this.chainClient.populateTransaction(tx);
57
+ });
58
+ }
59
+ /**
60
+ * Generates a transaction that will queue the proposal with the specified id to be executed.
61
+ * @param proposalId The id of the proposal to queue.
62
+ * @returns The transaction request.
63
+ */
64
+ queueProposal(proposalId) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ const governor = yield this.getGovernorContract();
67
+ const tx = yield governor.populateTransaction['queue(uint256)'](proposalId);
68
+ return yield this.chainClient.populateTransaction(tx);
69
+ });
70
+ }
71
+ /**
72
+ * Executes the proposal with the specified id.
73
+ * @param proposalId The id of the proposal to execute.
74
+ * @returns The transaction request.
75
+ */
76
+ executeProposal(proposalId) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const governor = yield this.getGovernorContract();
79
+ const tx = yield governor.populateTransaction['execute(uint256)'](proposalId);
80
+ return yield this.chainClient.populateTransaction(tx);
81
+ });
82
+ }
83
+ /**
84
+ * Submits a vote to the Mento Governor contract for the specified proposal.
85
+ * @param proposalId The id of the proposal to vote on.
86
+ * @param support Whether or not to support the proposal.
87
+ * @returns The transaction request.
88
+ */
89
+ castVote(proposalId, support) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ const governor = yield this.getGovernorContract();
92
+ const tx = yield governor.populateTransaction.castVote(proposalId, support);
93
+ return yield this.chainClient.populateTransaction(tx);
94
+ });
95
+ }
96
+ /**
97
+ * Cancels the proposal with the specified id.
98
+ * @param proposalId The id of the proposal to vote on.
99
+ * @param support Whether or not to support the proposal.
100
+ * @returns The transaction request.
101
+ */
102
+ cancelProposal(proposalId) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ const governor = yield this.getGovernorContract();
105
+ const tx = yield governor.populateTransaction.cancel(proposalId);
106
+ return yield this.chainClient.populateTransaction(tx);
107
+ });
108
+ }
109
+ /**
110
+ * Returns the state of the proposal with the specified id.
111
+ * @param proposalId The id of the proposal to get the state of.
112
+ * @returns The state of the proposal.
113
+ */
114
+ getProposalState(proposalId) {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ const governor = yield this.getGovernorContract();
117
+ const state = (yield governor.functions.state(proposalId))[0];
118
+ return types_1.ProposalState[state];
119
+ });
120
+ }
121
+ /**
122
+ * This function validates the args that are to be used in the createProposal function.
123
+ * @param targets The addresses of the contracts to be called during proposal execution.
124
+ * @param values The values to be passed to the calls to the target contracts.
125
+ * @param calldatas The calldata to be passed to the calls to the target contracts.
126
+ * @param description A human readable description of the proposal.
127
+ */
128
+ validateProposalArgs(targets, values, calldatas, description) {
129
+ if (!targets || targets.length === 0) {
130
+ throw new Error('Targets must be specified');
131
+ }
132
+ if (!values || values.length === 0) {
133
+ throw new Error('Values must be specified');
134
+ }
135
+ if (!calldatas || calldatas.length === 0) {
136
+ throw new Error('Calldatas must be specified');
137
+ }
138
+ if (!description) {
139
+ throw new Error('Description must be specified');
140
+ }
141
+ if (targets.length !== values.length ||
142
+ targets.length !== calldatas.length) {
143
+ throw new Error('Targets, values, and calldatas must all have the same length');
144
+ }
145
+ }
146
+ }
147
+ exports.Governance = Governance;
@@ -1 +1,4 @@
1
1
  export * from './mento';
2
+ export * from './governance';
3
+ export * from './utils';
4
+ export { ContractAddresses } from './types';
package/dist/cjs/index.js CHANGED
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  __exportStar(require("./mento"), exports);
19
+ __exportStar(require("./governance"), exports);
20
+ __exportStar(require("./utils"), exports);
package/dist/cjs/mento.js CHANGED
@@ -261,7 +261,7 @@ class Mento {
261
261
  const breakerBox = mento_core_ts_1.IBreakerBox__factory.connect(breakerBoxAddr, this.signerOrProvider);
262
262
  const currentMode = yield breakerBox.getRateFeedTradingMode(exchangeConfig.config.referenceRateFeedID);
263
263
  const BI_DIRECTIONAL_TRADING_MODE = 0;
264
- return currentMode.toNumber() == BI_DIRECTIONAL_TRADING_MODE;
264
+ return currentMode == BI_DIRECTIONAL_TRADING_MODE;
265
265
  });
266
266
  }
267
267
  /**
@@ -1,3 +1,4 @@
1
+ import { ethers, providers } from 'ethers';
1
2
  export type Address = string;
2
3
  export interface TradingLimit {
3
4
  asset: Address;
@@ -20,3 +21,30 @@ export interface TradingLimitsState {
20
21
  netflow1: number;
21
22
  netflowGlobal: number;
22
23
  }
24
+ export interface ContractAddressMap {
25
+ [chainId: string]: ContractAddresses;
26
+ }
27
+ export interface ContractAddresses {
28
+ GovernanceFactory: string;
29
+ Airgrab: string;
30
+ Emission: string;
31
+ MentoGovernor: string;
32
+ MentoToken: string;
33
+ TimelockController: string;
34
+ Locking: string;
35
+ }
36
+ export declare enum ProposalState {
37
+ PENDING = 0,
38
+ ACTIVE = 1,
39
+ CANCELED = 2,
40
+ DEFEATED = 3,
41
+ SUCCEEDED = 4,
42
+ QUEUED = 5,
43
+ EXPIRED = 6,
44
+ EXECUTED = 7
45
+ }
46
+ export interface IChainClient {
47
+ getSigner(): Promise<ethers.Signer | providers.Provider>;
48
+ getChainId(): Promise<number>;
49
+ populateTransaction(tx: ethers.PopulatedTransaction): Promise<providers.TransactionRequest>;
50
+ }
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 = {}));
@@ -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,29 @@
1
+ {
2
+ "42220": {
3
+ "GovernanceFactory": "",
4
+ "Airgrab": "",
5
+ "Emission": "",
6
+ "MentoGovernor": "",
7
+ "MentoToken": "",
8
+ "TimelockController": "",
9
+ "Locking": ""
10
+ },
11
+ "62320": {
12
+ "GovernanceFactory": "0x77645271665AdDF195202dEf1ad3cA678B442411",
13
+ "Airgrab": "0x349aa8910577A6fE16cA7b98b5A135d14CE4dF9f",
14
+ "Emission": "0xcd427DDB27D835E5353312e7897bb9ad35F0E214",
15
+ "MentoGovernor": "0x5dFE8CC7743C636a86bED8F8d0de982d502E22fC",
16
+ "MentoToken": "0xD2f4f160BAF7D88a7A9189b03D0B3AA6A5D9775B",
17
+ "TimelockController": "0xb5977b1d208ef35FAf97A9534Dd849c356F362C5",
18
+ "Locking": "0x831DAfC0912e1c2aBa2Da90668c0856d48a8C06b"
19
+ },
20
+ "44787": {
21
+ "GovernanceFactory": "0xD4079B322c392D6b196f90AA4c439fC2C16d6770",
22
+ "Airgrab": "0x281fA47f59456fA04DF699539fA4b1F25e7769A3",
23
+ "Emission": "0x8D1267bFf3f8166AEB2B58217b74188d1fe326f3",
24
+ "MentoGovernor": "0x84382a356c1Dc6ada21997E64dc72e5a7AcF5826",
25
+ "MentoToken": "0x53De3F938c64baB8C621c8A3C5000b385afE2404",
26
+ "TimelockController": "0x2AFC4a1e7928Fb3bfC81076740d3142FF8B1DE05",
27
+ "Locking": "0x65a1271ce7B2ec8D564A4Bc752E13A36a46e81B8"
28
+ }
29
+ }
@@ -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
+ }
@@ -1 +1,4 @@
1
1
  export * from './mento';
2
+ export * from './governance';
3
+ export * from './utils';
4
+ export { ContractAddresses } from './types';
package/dist/esm/index.js CHANGED
@@ -1,2 +1,4 @@
1
1
  /* istanbul ignore file */
2
2
  export * from './mento';
3
+ export * from './governance';
4
+ export * from './utils';
package/dist/esm/mento.js CHANGED
@@ -258,7 +258,7 @@ export class Mento {
258
258
  const breakerBox = IBreakerBox__factory.connect(breakerBoxAddr, this.signerOrProvider);
259
259
  const currentMode = yield breakerBox.getRateFeedTradingMode(exchangeConfig.config.referenceRateFeedID);
260
260
  const BI_DIRECTIONAL_TRADING_MODE = 0;
261
- return currentMode.toNumber() == BI_DIRECTIONAL_TRADING_MODE;
261
+ return currentMode == BI_DIRECTIONAL_TRADING_MODE;
262
262
  });
263
263
  }
264
264
  /**
@@ -1,3 +1,4 @@
1
+ import { ethers, providers } from 'ethers';
1
2
  export type Address = string;
2
3
  export interface TradingLimit {
3
4
  asset: Address;
@@ -20,3 +21,30 @@ export interface TradingLimitsState {
20
21
  netflow1: number;
21
22
  netflowGlobal: number;
22
23
  }
24
+ export interface ContractAddressMap {
25
+ [chainId: string]: ContractAddresses;
26
+ }
27
+ export interface ContractAddresses {
28
+ GovernanceFactory: string;
29
+ Airgrab: string;
30
+ Emission: string;
31
+ MentoGovernor: string;
32
+ MentoToken: string;
33
+ TimelockController: string;
34
+ Locking: string;
35
+ }
36
+ export declare enum ProposalState {
37
+ PENDING = 0,
38
+ ACTIVE = 1,
39
+ CANCELED = 2,
40
+ DEFEATED = 3,
41
+ SUCCEEDED = 4,
42
+ QUEUED = 5,
43
+ EXPIRED = 6,
44
+ EXECUTED = 7
45
+ }
46
+ export interface IChainClient {
47
+ getSigner(): Promise<ethers.Signer | providers.Provider>;
48
+ getChainId(): Promise<number>;
49
+ populateTransaction(tx: ethers.PopulatedTransaction): Promise<providers.TransactionRequest>;
50
+ }
package/dist/esm/types.js CHANGED
@@ -1 +1,11 @@
1
- export {};
1
+ export var ProposalState;
2
+ (function (ProposalState) {
3
+ ProposalState[ProposalState["PENDING"] = 0] = "PENDING";
4
+ ProposalState[ProposalState["ACTIVE"] = 1] = "ACTIVE";
5
+ ProposalState[ProposalState["CANCELED"] = 2] = "CANCELED";
6
+ ProposalState[ProposalState["DEFEATED"] = 3] = "DEFEATED";
7
+ ProposalState[ProposalState["SUCCEEDED"] = 4] = "SUCCEEDED";
8
+ ProposalState[ProposalState["QUEUED"] = 5] = "QUEUED";
9
+ ProposalState[ProposalState["EXPIRED"] = 6] = "EXPIRED";
10
+ ProposalState[ProposalState["EXECUTED"] = 7] = "EXECUTED";
11
+ })(ProposalState || (ProposalState = {}));
@@ -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/esm/utils.js CHANGED
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { constants, Contract, providers, Signer } from 'ethers';
11
+ import contractAddresses from './contracts.json';
11
12
  /**
12
13
  * Ensures that given signer is truly a a connected signer
13
14
  * @param signer an ethers signer
@@ -88,3 +89,11 @@ export function increaseAllowance(tokenAddr, spender, amount, signerOrProvider)
88
89
  return yield contract.populateTransaction.increaseAllowance(spender, amount);
89
90
  });
90
91
  }
92
+ export function getContractsByChainId(chainId) {
93
+ const addresses = contractAddresses;
94
+ const contracts = addresses[chainId];
95
+ if (!contracts) {
96
+ throw new Error(`No contracts found for chainId ${chainId}`);
97
+ }
98
+ return contracts;
99
+ }
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": "0.1.5",
4
+ "version": "0.2.1",
5
5
  "license": "MIT",
6
6
  "author": "Mento Labs",
7
7
  "keywords": [
@@ -77,7 +77,7 @@
77
77
  "typescript": "^4.9.5"
78
78
  },
79
79
  "dependencies": {
80
- "@mento-protocol/mento-core-ts": "^0.1.1"
80
+ "@mento-protocol/mento-core-ts": "^0.2.0"
81
81
  },
82
82
  "peerDependencies": {
83
83
  "ethers": "^5.7"