@mento-protocol/mento-sdk 0.2.8 → 1.0.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.
@@ -48,13 +48,13 @@ exports.addresses = {
48
48
  SortedOracles: '0xFdd8bD58115FfBf04e47411c1d228eCC45E93075',
49
49
  },
50
50
  [enums_1.ChainId.BAKLAVA]: {
51
- GovernanceFactory: '0x77645271665AdDF195202dEf1ad3cA678B442411',
52
- Airgrab: '0x349aa8910577A6fE16cA7b98b5A135d14CE4dF9f',
53
- Emission: '0xcd427DDB27D835E5353312e7897bb9ad35F0E214',
54
- MentoGovernor: '0x5dFE8CC7743C636a86bED8F8d0de982d502E22fC',
55
- MentoToken: '0xD2f4f160BAF7D88a7A9189b03D0B3AA6A5D9775B',
56
- TimelockController: '0xb5977b1d208ef35FAf97A9534Dd849c356F362C5',
57
- Locking: '0x831DAfC0912e1c2aBa2Da90668c0856d48a8C06b',
51
+ GovernanceFactory: '0xe23A28a92B95c743fC0F09c16a6b2E6D59F234Fa',
52
+ Airgrab: '0xNotDeployed',
53
+ Emission: '0xNotDeployed',
54
+ MentoGovernor: '0xf1873597aA9757f57BA8Ed84a3EDb2E3217EF09f',
55
+ MentoToken: '0x8942330eCB5A6c808aac3Aec3C6aab6D8CF436FE',
56
+ TimelockController: '0x8c045769087F9de69B70949ED7fC23c14Db71e20',
57
+ Locking: '0x1E15b108c51a0cAEAFf1a0E6f27A853Bde1AA2e6',
58
58
  Broker: '0x6723749339e320E1EFcd9f1B0D997ecb45587208',
59
59
  BiPoolManager: '0xFF9a3da00F42839CD6D33AD7adf50bCc97B41411',
60
60
  BreakerBox: '0x5Ea5A5F694F10de979BEeC7b8041E9f931F54bc7',
@@ -1,4 +1,6 @@
1
+ import { Address } from './tradingLimit';
1
2
  export interface TradingLimitsConfig {
3
+ asset: Address;
2
4
  timestep0: number;
3
5
  timestep1: number;
4
6
  limit0: number;
@@ -1,4 +1,6 @@
1
+ import { Address } from './tradingLimit';
1
2
  export interface TradingLimitsState {
3
+ asset: Address;
2
4
  lastUpdated0: number;
3
5
  lastUpdated1: number;
4
6
  netflow0: number;
@@ -24,6 +24,7 @@ function getLimitsConfig(broker, exchangeId, asset) {
24
24
  const limitId = getLimitId(exchangeId, asset);
25
25
  const cfg = yield broker.tradingLimitsConfig(limitId);
26
26
  return {
27
+ asset,
27
28
  timestep0: cfg['timestep0'],
28
29
  timestep1: cfg['timestep1'],
29
30
  limit0: cfg['limit0'],
@@ -54,6 +55,7 @@ function getLimitsState(broker, exchangeId, asset) {
54
55
  const isL0Outdated = isL0Enabled && nowEpoch > state['lastUpdated0'] + cfg.timestep0;
55
56
  const isL1Outdated = isL1Enabled && nowEpoch > state['lastUpdated1'] + cfg.timestep1;
56
57
  return {
58
+ asset,
57
59
  lastUpdated0: isL0Outdated ? nowEpoch : state['lastUpdated0'],
58
60
  lastUpdated1: isL1Outdated ? nowEpoch : state['lastUpdated1'],
59
61
  netflow0: isL0Outdated ? 0 : state['netflow0'],
@@ -102,6 +104,12 @@ function getLimits(broker, exchangeId, asset) {
102
104
  until: timestampIn2030,
103
105
  });
104
106
  }
107
+ // Limits with a smaller timeframe are restricted by the ones with a larger one
108
+ // e.g: if maxIn is 0 in LG, it should also be 0 in L1 and L0
109
+ for (let i = limits.length - 1; i > 0; i--) {
110
+ limits[i - 1].maxIn = Math.min(limits[i - 1].maxIn, limits[i].maxIn);
111
+ limits[i - 1].maxOut = Math.min(limits[i - 1].maxOut, limits[i].maxOut);
112
+ }
105
113
  return limits;
106
114
  });
107
115
  }
@@ -138,15 +138,15 @@ export declare class Mento {
138
138
  */
139
139
  getTradingLimits(exchangeId: string): Promise<TradingLimit[]>;
140
140
  /**
141
- * Returns the trading limits configuration for a given exchange id
141
+ * Returns the trading limits configurations for a given exchange id
142
142
  * @param exchangeId the id of the exchange
143
143
  * @returns the trading limits configuration
144
144
  */
145
- getTradingLimitConfig(exchangeId: string): Promise<TradingLimitsConfig>;
145
+ getTradingLimitConfig(exchangeId: string): Promise<TradingLimitsConfig[]>;
146
146
  /**
147
147
  * Returns the trading limits state for a given exchange id
148
148
  * @param exchangeId the id of the exchange
149
149
  * @returns the trading limits state
150
150
  */
151
- getTradingLimitState(exchangeId: string): Promise<TradingLimitsState>;
151
+ getTradingLimitState(exchangeId: string): Promise<TradingLimitsState[]>;
152
152
  }
package/dist/cjs/mento.js CHANGED
@@ -277,12 +277,13 @@ class Mento {
277
277
  return __awaiter(this, void 0, void 0, function* () {
278
278
  const exchange = yield this.getExchangeById(exchangeId);
279
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);
280
+ const asset0Limits = yield (0, limits_1.getLimits)(broker, exchangeId, exchange.assets[0]);
281
+ const asset1Limits = yield (0, limits_1.getLimits)(broker, exchangeId, exchange.assets[1]);
282
+ return asset0Limits.concat(asset1Limits);
282
283
  });
283
284
  }
284
285
  /**
285
- * Returns the trading limits configuration for a given exchange id
286
+ * Returns the trading limits configurations for a given exchange id
286
287
  * @param exchangeId the id of the exchange
287
288
  * @returns the trading limits configuration
288
289
  */
@@ -290,8 +291,15 @@ class Mento {
290
291
  return __awaiter(this, void 0, void 0, function* () {
291
292
  const exchange = yield this.getExchangeById(exchangeId);
292
293
  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);
294
+ const cfgs = [];
295
+ for (const asset of exchange.assets) {
296
+ const limitCfg = yield (0, limits_1.getLimitsConfig)(broker, exchangeId, asset);
297
+ const isLimitConfigured = limitCfg.flags > 0;
298
+ if (isLimitConfigured) {
299
+ cfgs.push(limitCfg);
300
+ }
301
+ }
302
+ return cfgs;
295
303
  });
296
304
  }
297
305
  /**
@@ -301,10 +309,9 @@ class Mento {
301
309
  */
302
310
  getTradingLimitState(exchangeId) {
303
311
  return __awaiter(this, void 0, void 0, function* () {
304
- const exchange = yield this.getExchangeById(exchangeId);
305
312
  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);
313
+ const configuredLimitCfgs = yield this.getTradingLimitConfig(exchangeId);
314
+ return yield Promise.all(configuredLimitCfgs.map((cfg) => __awaiter(this, void 0, void 0, function* () { return yield (0, limits_1.getLimitsState)(broker, exchangeId, cfg.asset); })));
308
315
  });
309
316
  }
310
317
  }
@@ -45,13 +45,13 @@ export const addresses = {
45
45
  SortedOracles: '0xFdd8bD58115FfBf04e47411c1d228eCC45E93075',
46
46
  },
47
47
  [ChainId.BAKLAVA]: {
48
- GovernanceFactory: '0x77645271665AdDF195202dEf1ad3cA678B442411',
49
- Airgrab: '0x349aa8910577A6fE16cA7b98b5A135d14CE4dF9f',
50
- Emission: '0xcd427DDB27D835E5353312e7897bb9ad35F0E214',
51
- MentoGovernor: '0x5dFE8CC7743C636a86bED8F8d0de982d502E22fC',
52
- MentoToken: '0xD2f4f160BAF7D88a7A9189b03D0B3AA6A5D9775B',
53
- TimelockController: '0xb5977b1d208ef35FAf97A9534Dd849c356F362C5',
54
- Locking: '0x831DAfC0912e1c2aBa2Da90668c0856d48a8C06b',
48
+ GovernanceFactory: '0xe23A28a92B95c743fC0F09c16a6b2E6D59F234Fa',
49
+ Airgrab: '0xNotDeployed',
50
+ Emission: '0xNotDeployed',
51
+ MentoGovernor: '0xf1873597aA9757f57BA8Ed84a3EDb2E3217EF09f',
52
+ MentoToken: '0x8942330eCB5A6c808aac3Aec3C6aab6D8CF436FE',
53
+ TimelockController: '0x8c045769087F9de69B70949ED7fC23c14Db71e20',
54
+ Locking: '0x1E15b108c51a0cAEAFf1a0E6f27A853Bde1AA2e6',
55
55
  Broker: '0x6723749339e320E1EFcd9f1B0D997ecb45587208',
56
56
  BiPoolManager: '0xFF9a3da00F42839CD6D33AD7adf50bCc97B41411',
57
57
  BreakerBox: '0x5Ea5A5F694F10de979BEeC7b8041E9f931F54bc7',
@@ -1,4 +1,6 @@
1
+ import { Address } from './tradingLimit';
1
2
  export interface TradingLimitsConfig {
3
+ asset: Address;
2
4
  timestep0: number;
3
5
  timestep1: number;
4
6
  limit0: number;
@@ -1,4 +1,6 @@
1
+ import { Address } from './tradingLimit';
1
2
  export interface TradingLimitsState {
3
+ asset: Address;
2
4
  lastUpdated0: number;
3
5
  lastUpdated1: number;
4
6
  netflow0: number;
@@ -21,6 +21,7 @@ export function getLimitsConfig(broker, exchangeId, asset) {
21
21
  const limitId = getLimitId(exchangeId, asset);
22
22
  const cfg = yield broker.tradingLimitsConfig(limitId);
23
23
  return {
24
+ asset,
24
25
  timestep0: cfg['timestep0'],
25
26
  timestep1: cfg['timestep1'],
26
27
  limit0: cfg['limit0'],
@@ -50,6 +51,7 @@ export function getLimitsState(broker, exchangeId, asset) {
50
51
  const isL0Outdated = isL0Enabled && nowEpoch > state['lastUpdated0'] + cfg.timestep0;
51
52
  const isL1Outdated = isL1Enabled && nowEpoch > state['lastUpdated1'] + cfg.timestep1;
52
53
  return {
54
+ asset,
53
55
  lastUpdated0: isL0Outdated ? nowEpoch : state['lastUpdated0'],
54
56
  lastUpdated1: isL1Outdated ? nowEpoch : state['lastUpdated1'],
55
57
  netflow0: isL0Outdated ? 0 : state['netflow0'],
@@ -97,6 +99,12 @@ export function getLimits(broker, exchangeId, asset) {
97
99
  until: timestampIn2030,
98
100
  });
99
101
  }
102
+ // Limits with a smaller timeframe are restricted by the ones with a larger one
103
+ // e.g: if maxIn is 0 in LG, it should also be 0 in L1 and L0
104
+ for (let i = limits.length - 1; i > 0; i--) {
105
+ limits[i - 1].maxIn = Math.min(limits[i - 1].maxIn, limits[i].maxIn);
106
+ limits[i - 1].maxOut = Math.min(limits[i - 1].maxOut, limits[i].maxOut);
107
+ }
100
108
  return limits;
101
109
  });
102
110
  }
@@ -138,15 +138,15 @@ export declare class Mento {
138
138
  */
139
139
  getTradingLimits(exchangeId: string): Promise<TradingLimit[]>;
140
140
  /**
141
- * Returns the trading limits configuration for a given exchange id
141
+ * Returns the trading limits configurations for a given exchange id
142
142
  * @param exchangeId the id of the exchange
143
143
  * @returns the trading limits configuration
144
144
  */
145
- getTradingLimitConfig(exchangeId: string): Promise<TradingLimitsConfig>;
145
+ getTradingLimitConfig(exchangeId: string): Promise<TradingLimitsConfig[]>;
146
146
  /**
147
147
  * Returns the trading limits state for a given exchange id
148
148
  * @param exchangeId the id of the exchange
149
149
  * @returns the trading limits state
150
150
  */
151
- getTradingLimitState(exchangeId: string): Promise<TradingLimitsState>;
151
+ getTradingLimitState(exchangeId: string): Promise<TradingLimitsState[]>;
152
152
  }
package/dist/esm/mento.js CHANGED
@@ -274,12 +274,13 @@ export class Mento {
274
274
  return __awaiter(this, void 0, void 0, function* () {
275
275
  const exchange = yield this.getExchangeById(exchangeId);
276
276
  const broker = Broker__factory.connect(this.broker.address, this.signerOrProvider);
277
- const assetWithLimit = exchange.assets[0]; // currently limits are configured only on asset0
278
- return getLimits(broker, exchangeId, assetWithLimit);
277
+ const asset0Limits = yield getLimits(broker, exchangeId, exchange.assets[0]);
278
+ const asset1Limits = yield getLimits(broker, exchangeId, exchange.assets[1]);
279
+ return asset0Limits.concat(asset1Limits);
279
280
  });
280
281
  }
281
282
  /**
282
- * Returns the trading limits configuration for a given exchange id
283
+ * Returns the trading limits configurations for a given exchange id
283
284
  * @param exchangeId the id of the exchange
284
285
  * @returns the trading limits configuration
285
286
  */
@@ -287,8 +288,15 @@ export class Mento {
287
288
  return __awaiter(this, void 0, void 0, function* () {
288
289
  const exchange = yield this.getExchangeById(exchangeId);
289
290
  const broker = Broker__factory.connect(this.broker.address, this.signerOrProvider);
290
- const assetWithLimit = exchange.assets[0]; // currently limits are configured only on asset0
291
- return getLimitsConfig(broker, exchangeId, assetWithLimit);
291
+ const cfgs = [];
292
+ for (const asset of exchange.assets) {
293
+ const limitCfg = yield getLimitsConfig(broker, exchangeId, asset);
294
+ const isLimitConfigured = limitCfg.flags > 0;
295
+ if (isLimitConfigured) {
296
+ cfgs.push(limitCfg);
297
+ }
298
+ }
299
+ return cfgs;
292
300
  });
293
301
  }
294
302
  /**
@@ -298,10 +306,9 @@ export class Mento {
298
306
  */
299
307
  getTradingLimitState(exchangeId) {
300
308
  return __awaiter(this, void 0, void 0, function* () {
301
- const exchange = yield this.getExchangeById(exchangeId);
302
309
  const broker = Broker__factory.connect(this.broker.address, this.signerOrProvider);
303
- const assetWithLimit = exchange.assets[0]; // currently limits are configured only on asset0
304
- return getLimitsState(broker, exchangeId, assetWithLimit);
310
+ const configuredLimitCfgs = yield this.getTradingLimitConfig(exchangeId);
311
+ return yield Promise.all(configuredLimitCfgs.map((cfg) => __awaiter(this, void 0, void 0, function* () { return yield getLimitsState(broker, exchangeId, cfg.asset); })));
305
312
  });
306
313
  }
307
314
  }
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.2.8",
4
+ "version": "1.0.1",
5
5
  "license": "MIT",
6
6
  "author": "Mento Labs",
7
7
  "keywords": [