@optimex-xyz/market-maker-sdk 0.8.0-staging-d94762b → 0.8.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/dist/index.d.mts CHANGED
@@ -5,7 +5,6 @@ type Environment = 'dev' | 'prelive' | 'production' | 'staging';
5
5
  interface EnvironmentConfig {
6
6
  backendUrl: string;
7
7
  rpcUrl: string;
8
- routerAddress: string;
9
8
  paymentAddressMap: Record<string, string>;
10
9
  protocolFetcherProxyAddress: string;
11
10
  }
@@ -37,7 +36,6 @@ declare class Config {
37
36
  get(): AppConfig;
38
37
  getBackendUrl(): string;
39
38
  getRpcUrl(): string;
40
- getRouterAddress(): string;
41
39
  getPaymentAddress(networkId: string): string | undefined;
42
40
  getProtocolFetcherAddress(): string;
43
41
  }
@@ -5569,11 +5567,13 @@ declare class RouterService implements ConfigObserver {
5569
5567
  private provider;
5570
5568
  private contract;
5571
5569
  constructor();
5570
+ onConfigUpdate(newConfig: AppConfig): void;
5572
5571
  /**
5573
- * Implementation of ConfigObserver interface
5574
- * Updates service when config changes
5572
+ * Force refresh the contract instance
5573
+ * Useful when router address might have changed
5575
5574
  */
5576
- onConfigUpdate(newConfig: AppConfig): void;
5575
+ refreshContract(): void;
5576
+ private getContract;
5577
5577
  getSigner(): Promise<string>;
5578
5578
  getHandler(fromChain: BytesLike, toChain: BytesLike): Promise<[string, string]>;
5579
5579
  getPMMSelection(tradeId: BytesLike): Promise<ITypes.PMMSelectionStructOutput>;
package/dist/index.d.ts CHANGED
@@ -5,7 +5,6 @@ type Environment = 'dev' | 'prelive' | 'production' | 'staging';
5
5
  interface EnvironmentConfig {
6
6
  backendUrl: string;
7
7
  rpcUrl: string;
8
- routerAddress: string;
9
8
  paymentAddressMap: Record<string, string>;
10
9
  protocolFetcherProxyAddress: string;
11
10
  }
@@ -37,7 +36,6 @@ declare class Config {
37
36
  get(): AppConfig;
38
37
  getBackendUrl(): string;
39
38
  getRpcUrl(): string;
40
- getRouterAddress(): string;
41
39
  getPaymentAddress(networkId: string): string | undefined;
42
40
  getProtocolFetcherAddress(): string;
43
41
  }
@@ -5569,11 +5567,13 @@ declare class RouterService implements ConfigObserver {
5569
5567
  private provider;
5570
5568
  private contract;
5571
5569
  constructor();
5570
+ onConfigUpdate(newConfig: AppConfig): void;
5572
5571
  /**
5573
- * Implementation of ConfigObserver interface
5574
- * Updates service when config changes
5572
+ * Force refresh the contract instance
5573
+ * Useful when router address might have changed
5575
5574
  */
5576
- onConfigUpdate(newConfig: AppConfig): void;
5575
+ refreshContract(): void;
5576
+ private getContract;
5577
5577
  getSigner(): Promise<string>;
5578
5578
  getHandler(fromChain: BytesLike, toChain: BytesLike): Promise<[string, string]>;
5579
5579
  getPMMSelection(tradeId: BytesLike): Promise<ITypes.PMMSelectionStructOutput>;
package/dist/index.js CHANGED
@@ -75,7 +75,6 @@ var environments = {
75
75
  dev: {
76
76
  backendUrl: "https://api-dev.bitdex.xyz",
77
77
  rpcUrl: "https://rpc-bitfi-p00c4t1rul.t.conduit.xyz",
78
- routerAddress: "0xe6DCDc525051F773EaC3e58B9b5f902D4E03fD55",
79
78
  protocolFetcherProxyAddress: "0x0267Fc04eE866b31907dEe123aBdCdB67d03B297",
80
79
  paymentAddressMap: {
81
80
  ethereum_sepolia: "0x1d8b58438D5Ccc8Fcb4b738C89078f7b4168C9c0"
@@ -84,7 +83,6 @@ var environments = {
84
83
  staging: {
85
84
  backendUrl: "https://api-stg.bitdex.xyz",
86
85
  rpcUrl: "https://rpc-bitfi-p00c4t1rul.t.conduit.xyz",
87
- routerAddress: "0x31C88ebd9E430455487b6a5c8971e8eF63e97ED4",
88
86
  protocolFetcherProxyAddress: "0x7c07151ca4DFd93F352Ab9B132A95866697c38c2",
89
87
  paymentAddressMap: {
90
88
  ethereum_sepolia: "0x7387DcCfE2f1D5F80b4ECDF91eF58541517e90D2"
@@ -93,7 +91,6 @@ var environments = {
93
91
  prelive: {
94
92
  backendUrl: "https://pre-api.optimex.xyz",
95
93
  rpcUrl: "https://rpc.optimex.xyz",
96
- routerAddress: "0xF7fedF4A250157010807E6eA60258E3B768149Ff",
97
94
  protocolFetcherProxyAddress: "0xFDEd4CEf9aE1E03D0BeF161262a266c1c157a32b",
98
95
  paymentAddressMap: {
99
96
  ethereum: "0x0A497AC4261E37FA4062762C23Cf3cB642C839b8"
@@ -102,7 +99,6 @@ var environments = {
102
99
  production: {
103
100
  backendUrl: "https://api.optimex.xyz",
104
101
  rpcUrl: "https://rpc.optimex.xyz",
105
- routerAddress: "0xF7fedF4A250157010807E6eA60258E3B768149Ff",
106
102
  protocolFetcherProxyAddress: "0xFDEd4CEf9aE1E03D0BeF161262a266c1c157a32b",
107
103
  paymentAddressMap: {
108
104
  ethereum: "0x0A497AC4261E37FA4062762C23Cf3cB642C839b8"
@@ -158,9 +154,6 @@ var Config = class {
158
154
  getRpcUrl() {
159
155
  return this.config.rpcUrl;
160
156
  }
161
- getRouterAddress() {
162
- return this.config.routerAddress;
163
- }
164
157
  getPaymentAddress(networkId) {
165
158
  return this.config.paymentAddressMap[networkId];
166
159
  }
@@ -4225,11 +4218,14 @@ var Signer__factory = class {
4225
4218
  Signer__factory.abi = _abi5;
4226
4219
 
4227
4220
  // src/services/router.service.ts
4221
+ var import_ethers7 = require("ethers");
4222
+
4223
+ // src/services/protocol.service.ts
4228
4224
  var import_ethers6 = require("ethers");
4229
- var RouterService = class {
4225
+ var ProtocolService = class {
4230
4226
  constructor() {
4231
4227
  this.provider = new import_ethers6.JsonRpcProvider(config.getRpcUrl());
4232
- this.contract = Router__factory.connect(config.getRouterAddress(), this.provider);
4228
+ this.contract = ProtocolFetcherProxy__factory.connect(config.getProtocolFetcherAddress(), this.provider);
4233
4229
  config.registerObserver(this);
4234
4230
  }
4235
4231
  /**
@@ -4238,38 +4234,93 @@ var RouterService = class {
4238
4234
  */
4239
4235
  onConfigUpdate(newConfig) {
4240
4236
  this.provider = new import_ethers6.JsonRpcProvider(newConfig.rpcUrl);
4241
- this.contract = Router__factory.connect(newConfig.routerAddress, this.provider);
4237
+ this.contract = ProtocolFetcherProxy__factory.connect(newConfig.protocolFetcherProxyAddress, this.provider);
4238
+ }
4239
+ async getCurrentPubkey(network) {
4240
+ return this.contract.getLatestMPCInfo(import_ethers6.ethers.toUtf8Bytes(network));
4241
+ }
4242
+ async getPFeeRate({
4243
+ fromNetworkId,
4244
+ fromTokenId,
4245
+ toNetworkId,
4246
+ toTokenId
4247
+ }) {
4248
+ const feeRate = await this.contract.getPFeeRate([
4249
+ import_ethers6.ethers.toUtf8Bytes(fromNetworkId),
4250
+ import_ethers6.ethers.toUtf8Bytes(fromTokenId),
4251
+ import_ethers6.ethers.toUtf8Bytes(toNetworkId),
4252
+ import_ethers6.ethers.toUtf8Bytes(toTokenId)
4253
+ ]);
4254
+ return Number(feeRate.toString());
4255
+ }
4256
+ async getRouter() {
4257
+ return this.contract.router();
4258
+ }
4259
+ };
4260
+ var protocolService = new ProtocolService();
4261
+
4262
+ // src/services/router.service.ts
4263
+ var RouterService = class {
4264
+ constructor() {
4265
+ this.contract = null;
4266
+ this.provider = new import_ethers7.JsonRpcProvider(config.getRpcUrl());
4267
+ config.registerObserver(this);
4268
+ }
4269
+ onConfigUpdate(newConfig) {
4270
+ this.provider = new import_ethers7.JsonRpcProvider(newConfig.rpcUrl);
4271
+ this.contract = null;
4272
+ }
4273
+ /**
4274
+ * Force refresh the contract instance
4275
+ * Useful when router address might have changed
4276
+ */
4277
+ refreshContract() {
4278
+ this.contract = null;
4279
+ }
4280
+ async getContract() {
4281
+ if (!this.contract) {
4282
+ const routerAddress = await protocolService.getRouter();
4283
+ this.contract = Router__factory.connect(routerAddress, this.provider);
4284
+ }
4285
+ return this.contract;
4242
4286
  }
4243
4287
  async getSigner() {
4244
- return await this.contract.SIGNER();
4288
+ const contract = await this.getContract();
4289
+ return await contract.SIGNER();
4245
4290
  }
4246
4291
  async getHandler(fromChain, toChain) {
4247
- return await this.contract.getHandler(fromChain, toChain);
4292
+ const contract = await this.getContract();
4293
+ return await contract.getHandler(fromChain, toChain);
4248
4294
  }
4249
4295
  async getPMMSelection(tradeId) {
4250
- return await this.contract.getPMMSelection(tradeId);
4296
+ const contract = await this.getContract();
4297
+ return await contract.getPMMSelection(tradeId);
4251
4298
  }
4252
4299
  async getSettlementPresigns(tradeId) {
4253
- return await this.contract.getSettlementPresigns(tradeId);
4300
+ const contract = await this.getContract();
4301
+ return await contract.getSettlementPresigns(tradeId);
4254
4302
  }
4255
4303
  async getFeeDetails(tradeId) {
4256
- return await this.contract.getFeeDetails(tradeId);
4304
+ const contract = await this.getContract();
4305
+ return await contract.getFeeDetails(tradeId);
4257
4306
  }
4258
4307
  async getTradeData(tradeId) {
4259
- return await this.contract.getTradeData(tradeId);
4308
+ const contract = await this.getContract();
4309
+ return await contract.getTradeData(tradeId);
4260
4310
  }
4261
4311
  async getManagement() {
4262
- return await this.contract.management();
4312
+ const contract = await this.getContract();
4313
+ return await contract.management();
4263
4314
  }
4264
4315
  };
4265
4316
  var routerService = new RouterService();
4266
4317
 
4267
4318
  // src/services/signer.service.ts
4268
- var import_ethers7 = require("ethers");
4319
+ var import_ethers8 = require("ethers");
4269
4320
  var SignerService = class {
4270
4321
  constructor() {
4271
4322
  this.routerService = routerService;
4272
- this.provider = new import_ethers7.JsonRpcProvider(config.getRpcUrl());
4323
+ this.provider = new import_ethers8.JsonRpcProvider(config.getRpcUrl());
4273
4324
  config.registerObserver(this);
4274
4325
  }
4275
4326
  /**
@@ -4277,7 +4328,7 @@ var SignerService = class {
4277
4328
  * Updates service when config changes
4278
4329
  */
4279
4330
  onConfigUpdate(newConfig) {
4280
- this.provider = new import_ethers7.JsonRpcProvider(newConfig.rpcUrl);
4331
+ this.provider = new import_ethers8.JsonRpcProvider(newConfig.rpcUrl);
4281
4332
  }
4282
4333
  async getDomain() {
4283
4334
  const signerAddress = await this.routerService.getSigner();
@@ -4621,20 +4672,20 @@ async function defaultDomain(signerHelper, provider) {
4621
4672
  }
4622
4673
 
4623
4674
  // src/signatures/getInfoHash.ts
4624
- var import_ethers8 = require("ethers");
4625
- var abiCoder = import_ethers8.AbiCoder.defaultAbiCoder();
4675
+ var import_ethers9 = require("ethers");
4676
+ var abiCoder = import_ethers9.AbiCoder.defaultAbiCoder();
4626
4677
  function getTradeIdsHash(tradeIds) {
4627
- return (0, import_ethers8.keccak256)(abiCoder.encode(["bytes32[]"], [tradeIds]));
4678
+ return (0, import_ethers9.keccak256)(abiCoder.encode(["bytes32[]"], [tradeIds]));
4628
4679
  }
4629
4680
  function getMakePaymentHash(tradeIds, signedAt, startIdx, paymentTxId) {
4630
- const bundlerHash = (0, import_ethers8.keccak256)(abiCoder.encode(["bytes32[]"], [tradeIds]));
4631
- const infoHash = (0, import_ethers8.keccak256)(
4681
+ const bundlerHash = (0, import_ethers9.keccak256)(abiCoder.encode(["bytes32[]"], [tradeIds]));
4682
+ const infoHash = (0, import_ethers9.keccak256)(
4632
4683
  abiCoder.encode(["uint64", "uint256", "bytes32", "bytes"], [signedAt, startIdx, bundlerHash, paymentTxId])
4633
4684
  );
4634
4685
  return infoHash;
4635
4686
  }
4636
4687
  function getCommitInfoHash(pmmId, pmmRecvAddr, toChain, toToken, amountOut, expiry) {
4637
- const infoHash = (0, import_ethers8.keccak256)(
4688
+ const infoHash = (0, import_ethers9.keccak256)(
4638
4689
  abiCoder.encode(
4639
4690
  ["bytes32", "bytes", "bytes", "bytes", "uint256", "uint64"],
4640
4691
  [pmmId, pmmRecvAddr, toChain, toToken, amountOut, expiry]
@@ -4644,7 +4695,7 @@ function getCommitInfoHash(pmmId, pmmRecvAddr, toChain, toToken, amountOut, expi
4644
4695
  }
4645
4696
 
4646
4697
  // src/signatures/getSignature.ts
4647
- var import_ethers9 = require("ethers");
4698
+ var import_ethers10 = require("ethers");
4648
4699
 
4649
4700
  // src/signatures/types.ts
4650
4701
  var presignType = {
@@ -4711,7 +4762,7 @@ function getSignatureType(type) {
4711
4762
  async function getSigner(provider, signerHelper, tradeId, infoHash, type, signature) {
4712
4763
  const values = { tradeId, infoHash };
4713
4764
  const contractDomain = await defaultDomain(signerHelper, provider);
4714
- return (0, import_ethers9.verifyTypedData)(contractDomain, getSignatureType(type), values, signature);
4765
+ return (0, import_ethers10.verifyTypedData)(contractDomain, getSignatureType(type), values, signature);
4715
4766
  }
4716
4767
  async function getSignature(Signer2, provider, signerHelper, tradeId, infoHash, type, domain) {
4717
4768
  const contractDomain = await defaultDomain(signerHelper, provider);
package/dist/index.mjs CHANGED
@@ -9,7 +9,6 @@ var environments = {
9
9
  dev: {
10
10
  backendUrl: "https://api-dev.bitdex.xyz",
11
11
  rpcUrl: "https://rpc-bitfi-p00c4t1rul.t.conduit.xyz",
12
- routerAddress: "0xe6DCDc525051F773EaC3e58B9b5f902D4E03fD55",
13
12
  protocolFetcherProxyAddress: "0x0267Fc04eE866b31907dEe123aBdCdB67d03B297",
14
13
  paymentAddressMap: {
15
14
  ethereum_sepolia: "0x1d8b58438D5Ccc8Fcb4b738C89078f7b4168C9c0"
@@ -18,7 +17,6 @@ var environments = {
18
17
  staging: {
19
18
  backendUrl: "https://api-stg.bitdex.xyz",
20
19
  rpcUrl: "https://rpc-bitfi-p00c4t1rul.t.conduit.xyz",
21
- routerAddress: "0x31C88ebd9E430455487b6a5c8971e8eF63e97ED4",
22
20
  protocolFetcherProxyAddress: "0x7c07151ca4DFd93F352Ab9B132A95866697c38c2",
23
21
  paymentAddressMap: {
24
22
  ethereum_sepolia: "0x7387DcCfE2f1D5F80b4ECDF91eF58541517e90D2"
@@ -27,7 +25,6 @@ var environments = {
27
25
  prelive: {
28
26
  backendUrl: "https://pre-api.optimex.xyz",
29
27
  rpcUrl: "https://rpc.optimex.xyz",
30
- routerAddress: "0xF7fedF4A250157010807E6eA60258E3B768149Ff",
31
28
  protocolFetcherProxyAddress: "0xFDEd4CEf9aE1E03D0BeF161262a266c1c157a32b",
32
29
  paymentAddressMap: {
33
30
  ethereum: "0x0A497AC4261E37FA4062762C23Cf3cB642C839b8"
@@ -36,7 +33,6 @@ var environments = {
36
33
  production: {
37
34
  backendUrl: "https://api.optimex.xyz",
38
35
  rpcUrl: "https://rpc.optimex.xyz",
39
- routerAddress: "0xF7fedF4A250157010807E6eA60258E3B768149Ff",
40
36
  protocolFetcherProxyAddress: "0xFDEd4CEf9aE1E03D0BeF161262a266c1c157a32b",
41
37
  paymentAddressMap: {
42
38
  ethereum: "0x0A497AC4261E37FA4062762C23Cf3cB642C839b8"
@@ -92,9 +88,6 @@ var Config = class {
92
88
  getRpcUrl() {
93
89
  return this.config.rpcUrl;
94
90
  }
95
- getRouterAddress() {
96
- return this.config.routerAddress;
97
- }
98
91
  getPaymentAddress(networkId) {
99
92
  return this.config.paymentAddressMap[networkId];
100
93
  }
@@ -4159,11 +4152,14 @@ var Signer__factory = class {
4159
4152
  Signer__factory.abi = _abi5;
4160
4153
 
4161
4154
  // src/services/router.service.ts
4162
- import { JsonRpcProvider } from "ethers";
4163
- var RouterService = class {
4155
+ import { JsonRpcProvider as JsonRpcProvider2 } from "ethers";
4156
+
4157
+ // src/services/protocol.service.ts
4158
+ import { ethers, JsonRpcProvider } from "ethers";
4159
+ var ProtocolService = class {
4164
4160
  constructor() {
4165
4161
  this.provider = new JsonRpcProvider(config.getRpcUrl());
4166
- this.contract = Router__factory.connect(config.getRouterAddress(), this.provider);
4162
+ this.contract = ProtocolFetcherProxy__factory.connect(config.getProtocolFetcherAddress(), this.provider);
4167
4163
  config.registerObserver(this);
4168
4164
  }
4169
4165
  /**
@@ -4172,38 +4168,93 @@ var RouterService = class {
4172
4168
  */
4173
4169
  onConfigUpdate(newConfig) {
4174
4170
  this.provider = new JsonRpcProvider(newConfig.rpcUrl);
4175
- this.contract = Router__factory.connect(newConfig.routerAddress, this.provider);
4171
+ this.contract = ProtocolFetcherProxy__factory.connect(newConfig.protocolFetcherProxyAddress, this.provider);
4172
+ }
4173
+ async getCurrentPubkey(network) {
4174
+ return this.contract.getLatestMPCInfo(ethers.toUtf8Bytes(network));
4175
+ }
4176
+ async getPFeeRate({
4177
+ fromNetworkId,
4178
+ fromTokenId,
4179
+ toNetworkId,
4180
+ toTokenId
4181
+ }) {
4182
+ const feeRate = await this.contract.getPFeeRate([
4183
+ ethers.toUtf8Bytes(fromNetworkId),
4184
+ ethers.toUtf8Bytes(fromTokenId),
4185
+ ethers.toUtf8Bytes(toNetworkId),
4186
+ ethers.toUtf8Bytes(toTokenId)
4187
+ ]);
4188
+ return Number(feeRate.toString());
4189
+ }
4190
+ async getRouter() {
4191
+ return this.contract.router();
4192
+ }
4193
+ };
4194
+ var protocolService = new ProtocolService();
4195
+
4196
+ // src/services/router.service.ts
4197
+ var RouterService = class {
4198
+ constructor() {
4199
+ this.contract = null;
4200
+ this.provider = new JsonRpcProvider2(config.getRpcUrl());
4201
+ config.registerObserver(this);
4202
+ }
4203
+ onConfigUpdate(newConfig) {
4204
+ this.provider = new JsonRpcProvider2(newConfig.rpcUrl);
4205
+ this.contract = null;
4206
+ }
4207
+ /**
4208
+ * Force refresh the contract instance
4209
+ * Useful when router address might have changed
4210
+ */
4211
+ refreshContract() {
4212
+ this.contract = null;
4213
+ }
4214
+ async getContract() {
4215
+ if (!this.contract) {
4216
+ const routerAddress = await protocolService.getRouter();
4217
+ this.contract = Router__factory.connect(routerAddress, this.provider);
4218
+ }
4219
+ return this.contract;
4176
4220
  }
4177
4221
  async getSigner() {
4178
- return await this.contract.SIGNER();
4222
+ const contract = await this.getContract();
4223
+ return await contract.SIGNER();
4179
4224
  }
4180
4225
  async getHandler(fromChain, toChain) {
4181
- return await this.contract.getHandler(fromChain, toChain);
4226
+ const contract = await this.getContract();
4227
+ return await contract.getHandler(fromChain, toChain);
4182
4228
  }
4183
4229
  async getPMMSelection(tradeId) {
4184
- return await this.contract.getPMMSelection(tradeId);
4230
+ const contract = await this.getContract();
4231
+ return await contract.getPMMSelection(tradeId);
4185
4232
  }
4186
4233
  async getSettlementPresigns(tradeId) {
4187
- return await this.contract.getSettlementPresigns(tradeId);
4234
+ const contract = await this.getContract();
4235
+ return await contract.getSettlementPresigns(tradeId);
4188
4236
  }
4189
4237
  async getFeeDetails(tradeId) {
4190
- return await this.contract.getFeeDetails(tradeId);
4238
+ const contract = await this.getContract();
4239
+ return await contract.getFeeDetails(tradeId);
4191
4240
  }
4192
4241
  async getTradeData(tradeId) {
4193
- return await this.contract.getTradeData(tradeId);
4242
+ const contract = await this.getContract();
4243
+ return await contract.getTradeData(tradeId);
4194
4244
  }
4195
4245
  async getManagement() {
4196
- return await this.contract.management();
4246
+ const contract = await this.getContract();
4247
+ return await contract.management();
4197
4248
  }
4198
4249
  };
4199
4250
  var routerService = new RouterService();
4200
4251
 
4201
4252
  // src/services/signer.service.ts
4202
- import { JsonRpcProvider as JsonRpcProvider2 } from "ethers";
4253
+ import { JsonRpcProvider as JsonRpcProvider3 } from "ethers";
4203
4254
  var SignerService = class {
4204
4255
  constructor() {
4205
4256
  this.routerService = routerService;
4206
- this.provider = new JsonRpcProvider2(config.getRpcUrl());
4257
+ this.provider = new JsonRpcProvider3(config.getRpcUrl());
4207
4258
  config.registerObserver(this);
4208
4259
  }
4209
4260
  /**
@@ -4211,7 +4262,7 @@ var SignerService = class {
4211
4262
  * Updates service when config changes
4212
4263
  */
4213
4264
  onConfigUpdate(newConfig) {
4214
- this.provider = new JsonRpcProvider2(newConfig.rpcUrl);
4265
+ this.provider = new JsonRpcProvider3(newConfig.rpcUrl);
4215
4266
  }
4216
4267
  async getDomain() {
4217
4268
  const signerAddress = await this.routerService.getSigner();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimex-xyz/market-maker-sdk",
3
- "version": "0.8.0-staging-d94762b",
3
+ "version": "0.8.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"