@optimex-xyz/market-maker-sdk 0.4.0 → 0.4.2

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
@@ -12,6 +12,7 @@ A comprehensive toolkit for implementing Private Market Makers (PMMs) in the cro
12
12
  - [2. Quick Start](#2-quick-start)
13
13
  - [2.1. Installation](#21-installation)
14
14
  - [2.2. Environment Setup](#22-environment-setup)
15
+ - [2.3. Available Environments](#23-available-environments)
15
16
  - [3. PMM Backend APIs](#3-pmm-backend-apis)
16
17
  - [3.1. Endpoint: `/indicative-quote`](#31-endpoint-indicative-quote)
17
18
  - [Description](#description)
@@ -110,9 +111,26 @@ yarn add @optimex-xyz/market-maker-sdk
110
111
 
111
112
  ### 2.2. Environment Setup
112
113
 
113
- | Variable | Development | Production |
114
- | -------- | ----------- | ---------- |
115
- | SDK_ENV | dev | production |
114
+ you can directly specify the environment
115
+
116
+ ```typescript
117
+ import { sdk, Environment } from '@optimex-xyz/market-maker-sdk'
118
+
119
+ // Change to development environment
120
+ sdk.setEnvironment('dev' as Environment)
121
+
122
+ // Change to production environment
123
+ sdk.setEnvironment('production' as Environment)
124
+ ```
125
+
126
+ ### 2.3. Available Environments
127
+
128
+ | Environment | Description |
129
+ | ------------ | -------------------------------------------------------------------- |
130
+ | `dev` | Development environment with test networks and staging services |
131
+ | `production` | Production environment with mainnet networks and production services |
132
+
133
+ Each environment includes specific configuration for backend URLs, RPC endpoints, router addresses, and payment addresses.
116
134
 
117
135
  ## 3. PMM Backend APIs
118
136
 
package/dist/index.d.mts CHANGED
@@ -11,10 +11,22 @@ interface EnvironmentConfig {
11
11
  interface AppConfig extends EnvironmentConfig {
12
12
  env: Environment;
13
13
  }
14
+ interface ConfigObserver {
15
+ onConfigUpdate(newConfig: AppConfig): void;
16
+ }
14
17
  declare class Config {
15
18
  private env;
16
19
  private config;
17
- constructor();
20
+ private observers;
21
+ constructor(env?: Environment);
22
+ /**
23
+ * Register a service as an observer to be notified of config changes
24
+ */
25
+ registerObserver(observer: ConfigObserver): void;
26
+ /**
27
+ * Remove a service from observers
28
+ */
29
+ unregisterObserver(observer: ConfigObserver): void;
18
30
  /**
19
31
  * Set the environment for the SDK
20
32
  * @param env The environment to use ('dev' or 'production')
@@ -31,10 +43,15 @@ declare const config: Config;
31
43
 
32
44
  declare class SDK {
33
45
  /**
34
- * Initialize the SDK with a specific environment
46
+ * Change the environment after initialization
35
47
  * @param env The environment to use ('dev' or 'production')
36
48
  */
37
49
  setEnvironment(env: Environment): void;
50
+ /**
51
+ * Get the current environment configuration
52
+ * @returns The current environment configuration
53
+ */
54
+ getConfig(): AppConfig;
38
55
  }
39
56
  declare const sdk: SDK;
40
57
 
@@ -4573,10 +4590,15 @@ declare namespace index {
4573
4590
  export { index_ERC20__factory as ERC20__factory, index_Payment__factory as Payment__factory, index_Router__factory as Router__factory, index_Signer__factory as Signer__factory };
4574
4591
  }
4575
4592
 
4576
- declare class RouterService {
4577
- private readonly provider;
4578
- private readonly contract;
4593
+ declare class RouterService implements ConfigObserver {
4594
+ private provider;
4595
+ private contract;
4579
4596
  constructor();
4597
+ /**
4598
+ * Implementation of ConfigObserver interface
4599
+ * Updates service when config changes
4600
+ */
4601
+ onConfigUpdate(newConfig: AppConfig): void;
4580
4602
  getSigner(): Promise<string>;
4581
4603
  getCurrentPubkey(network: string): Promise<ITypes.MPCInfoStructOutput>;
4582
4604
  getCurrentStage(tradeId: BytesLike): Promise<bigint>;
@@ -4603,10 +4625,15 @@ declare class RouterService {
4603
4625
  }
4604
4626
  declare const routerService: RouterService;
4605
4627
 
4606
- declare class SignerService {
4607
- private readonly provider;
4628
+ declare class SignerService implements ConfigObserver {
4629
+ private provider;
4608
4630
  private readonly routerService;
4609
4631
  constructor();
4632
+ /**
4633
+ * Implementation of ConfigObserver interface
4634
+ * Updates service when config changes
4635
+ */
4636
+ onConfigUpdate(newConfig: AppConfig): void;
4610
4637
  getDomain(): Promise<{
4611
4638
  name: string;
4612
4639
  version: string;
@@ -4647,9 +4674,14 @@ declare const SubmitSettlementResponseSchema: z.ZodObject<{
4647
4674
  }>;
4648
4675
  type SubmitSettlementRequest = z.infer<typeof SubmitSettlementRequestSchema>;
4649
4676
  type SubmitSettlementResponse = z.infer<typeof SubmitSettlementResponseSchema>;
4650
- declare class SolverService {
4651
- private readonly baseURL;
4677
+ declare class SolverService implements ConfigObserver {
4678
+ private baseURL;
4652
4679
  constructor();
4680
+ /**
4681
+ * Implementation of ConfigObserver interface
4682
+ * Updates service when config changes
4683
+ */
4684
+ onConfigUpdate(newConfig: AppConfig): void;
4653
4685
  /**
4654
4686
  * Submits a settlement transaction to the solver backend
4655
4687
  * @param params Settlement transaction parameters
@@ -4699,9 +4731,14 @@ declare const TokenSchema: z.ZodObject<{
4699
4731
  }>;
4700
4732
  type Token = z.infer<typeof TokenSchema>;
4701
4733
 
4702
- declare class TokenService {
4703
- private readonly baseURL;
4734
+ declare class TokenService implements ConfigObserver {
4735
+ private baseURL;
4704
4736
  constructor();
4737
+ /**
4738
+ * Implementation of ConfigObserver interface
4739
+ * Updates service when config changes
4740
+ */
4741
+ onConfigUpdate(newConfig: AppConfig): void;
4705
4742
  /**
4706
4743
  * Fetches all available tokens from the API
4707
4744
  * @returns Promise<Token[]> Array of tokens
@@ -4798,4 +4835,4 @@ declare function camelToSnakeCase(str: string): string;
4798
4835
  declare const ensureHexPrefix: (value: string) => string;
4799
4836
  declare const removeHexPrefix: (value: string) => string;
4800
4837
 
4801
- export { type AppConfig, type ERC20, ERC20__factory, type Environment, type EnvironmentConfig, ITypes, type Payment, Payment__factory, type Router, RouterService, Router__factory, SDK, SignatureType, type Signer, SignerService, Signer__factory, SolverService, type Token, TokenSchema, TokenService, camelToSnakeCase, config, confirmDepositType, confirmPaymentType, confirmSettlementType, convertToCamelCase, convertToSnakeCase, ensureHexPrefix, index as factories, getCommitInfoHash, getMakePaymentHash, getSignature, getSigner, getTradeIdsHash, makePaymentType, presignType, removeHexPrefix, rfqAuthenticationTypes, routerService, sdk, selectionType, signerService, snakeToCamelCase, solverService, tokenService };
4838
+ export { type AppConfig, type ConfigObserver, type ERC20, ERC20__factory, type Environment, type EnvironmentConfig, ITypes, type Payment, Payment__factory, type Router, RouterService, Router__factory, SDK, SignatureType, type Signer, SignerService, Signer__factory, SolverService, type Token, TokenSchema, TokenService, camelToSnakeCase, config, confirmDepositType, confirmPaymentType, confirmSettlementType, convertToCamelCase, convertToSnakeCase, ensureHexPrefix, index as factories, getCommitInfoHash, getMakePaymentHash, getSignature, getSigner, getTradeIdsHash, makePaymentType, presignType, removeHexPrefix, rfqAuthenticationTypes, routerService, sdk, selectionType, signerService, snakeToCamelCase, solverService, tokenService };
package/dist/index.d.ts CHANGED
@@ -11,10 +11,22 @@ interface EnvironmentConfig {
11
11
  interface AppConfig extends EnvironmentConfig {
12
12
  env: Environment;
13
13
  }
14
+ interface ConfigObserver {
15
+ onConfigUpdate(newConfig: AppConfig): void;
16
+ }
14
17
  declare class Config {
15
18
  private env;
16
19
  private config;
17
- constructor();
20
+ private observers;
21
+ constructor(env?: Environment);
22
+ /**
23
+ * Register a service as an observer to be notified of config changes
24
+ */
25
+ registerObserver(observer: ConfigObserver): void;
26
+ /**
27
+ * Remove a service from observers
28
+ */
29
+ unregisterObserver(observer: ConfigObserver): void;
18
30
  /**
19
31
  * Set the environment for the SDK
20
32
  * @param env The environment to use ('dev' or 'production')
@@ -31,10 +43,15 @@ declare const config: Config;
31
43
 
32
44
  declare class SDK {
33
45
  /**
34
- * Initialize the SDK with a specific environment
46
+ * Change the environment after initialization
35
47
  * @param env The environment to use ('dev' or 'production')
36
48
  */
37
49
  setEnvironment(env: Environment): void;
50
+ /**
51
+ * Get the current environment configuration
52
+ * @returns The current environment configuration
53
+ */
54
+ getConfig(): AppConfig;
38
55
  }
39
56
  declare const sdk: SDK;
40
57
 
@@ -4573,10 +4590,15 @@ declare namespace index {
4573
4590
  export { index_ERC20__factory as ERC20__factory, index_Payment__factory as Payment__factory, index_Router__factory as Router__factory, index_Signer__factory as Signer__factory };
4574
4591
  }
4575
4592
 
4576
- declare class RouterService {
4577
- private readonly provider;
4578
- private readonly contract;
4593
+ declare class RouterService implements ConfigObserver {
4594
+ private provider;
4595
+ private contract;
4579
4596
  constructor();
4597
+ /**
4598
+ * Implementation of ConfigObserver interface
4599
+ * Updates service when config changes
4600
+ */
4601
+ onConfigUpdate(newConfig: AppConfig): void;
4580
4602
  getSigner(): Promise<string>;
4581
4603
  getCurrentPubkey(network: string): Promise<ITypes.MPCInfoStructOutput>;
4582
4604
  getCurrentStage(tradeId: BytesLike): Promise<bigint>;
@@ -4603,10 +4625,15 @@ declare class RouterService {
4603
4625
  }
4604
4626
  declare const routerService: RouterService;
4605
4627
 
4606
- declare class SignerService {
4607
- private readonly provider;
4628
+ declare class SignerService implements ConfigObserver {
4629
+ private provider;
4608
4630
  private readonly routerService;
4609
4631
  constructor();
4632
+ /**
4633
+ * Implementation of ConfigObserver interface
4634
+ * Updates service when config changes
4635
+ */
4636
+ onConfigUpdate(newConfig: AppConfig): void;
4610
4637
  getDomain(): Promise<{
4611
4638
  name: string;
4612
4639
  version: string;
@@ -4647,9 +4674,14 @@ declare const SubmitSettlementResponseSchema: z.ZodObject<{
4647
4674
  }>;
4648
4675
  type SubmitSettlementRequest = z.infer<typeof SubmitSettlementRequestSchema>;
4649
4676
  type SubmitSettlementResponse = z.infer<typeof SubmitSettlementResponseSchema>;
4650
- declare class SolverService {
4651
- private readonly baseURL;
4677
+ declare class SolverService implements ConfigObserver {
4678
+ private baseURL;
4652
4679
  constructor();
4680
+ /**
4681
+ * Implementation of ConfigObserver interface
4682
+ * Updates service when config changes
4683
+ */
4684
+ onConfigUpdate(newConfig: AppConfig): void;
4653
4685
  /**
4654
4686
  * Submits a settlement transaction to the solver backend
4655
4687
  * @param params Settlement transaction parameters
@@ -4699,9 +4731,14 @@ declare const TokenSchema: z.ZodObject<{
4699
4731
  }>;
4700
4732
  type Token = z.infer<typeof TokenSchema>;
4701
4733
 
4702
- declare class TokenService {
4703
- private readonly baseURL;
4734
+ declare class TokenService implements ConfigObserver {
4735
+ private baseURL;
4704
4736
  constructor();
4737
+ /**
4738
+ * Implementation of ConfigObserver interface
4739
+ * Updates service when config changes
4740
+ */
4741
+ onConfigUpdate(newConfig: AppConfig): void;
4705
4742
  /**
4706
4743
  * Fetches all available tokens from the API
4707
4744
  * @returns Promise<Token[]> Array of tokens
@@ -4798,4 +4835,4 @@ declare function camelToSnakeCase(str: string): string;
4798
4835
  declare const ensureHexPrefix: (value: string) => string;
4799
4836
  declare const removeHexPrefix: (value: string) => string;
4800
4837
 
4801
- export { type AppConfig, type ERC20, ERC20__factory, type Environment, type EnvironmentConfig, ITypes, type Payment, Payment__factory, type Router, RouterService, Router__factory, SDK, SignatureType, type Signer, SignerService, Signer__factory, SolverService, type Token, TokenSchema, TokenService, camelToSnakeCase, config, confirmDepositType, confirmPaymentType, confirmSettlementType, convertToCamelCase, convertToSnakeCase, ensureHexPrefix, index as factories, getCommitInfoHash, getMakePaymentHash, getSignature, getSigner, getTradeIdsHash, makePaymentType, presignType, removeHexPrefix, rfqAuthenticationTypes, routerService, sdk, selectionType, signerService, snakeToCamelCase, solverService, tokenService };
4838
+ export { type AppConfig, type ConfigObserver, type ERC20, ERC20__factory, type Environment, type EnvironmentConfig, ITypes, type Payment, Payment__factory, type Router, RouterService, Router__factory, SDK, SignatureType, type Signer, SignerService, Signer__factory, SolverService, type Token, TokenSchema, TokenService, camelToSnakeCase, config, confirmDepositType, confirmPaymentType, confirmSettlementType, convertToCamelCase, convertToSnakeCase, ensureHexPrefix, index as factories, getCommitInfoHash, getMakePaymentHash, getSignature, getSigner, getTradeIdsHash, makePaymentType, presignType, removeHexPrefix, rfqAuthenticationTypes, routerService, sdk, selectionType, signerService, snakeToCamelCase, solverService, tokenService };
package/dist/index.js CHANGED
@@ -89,10 +89,23 @@ var environments = {
89
89
  }
90
90
  };
91
91
  var Config = class {
92
- constructor() {
93
- this.env = process.env.SDK_ENV || "production";
92
+ constructor(env = "production") {
93
+ this.observers = [];
94
+ this.env = env;
94
95
  this.config = this.validateAndGetConfig(this.env);
95
96
  }
97
+ /**
98
+ * Register a service as an observer to be notified of config changes
99
+ */
100
+ registerObserver(observer) {
101
+ this.observers.push(observer);
102
+ }
103
+ /**
104
+ * Remove a service from observers
105
+ */
106
+ unregisterObserver(observer) {
107
+ this.observers = this.observers.filter((obs) => obs !== observer);
108
+ }
96
109
  /**
97
110
  * Set the environment for the SDK
98
111
  * @param env The environment to use ('dev' or 'production')
@@ -103,6 +116,8 @@ var Config = class {
103
116
  }
104
117
  this.env = env;
105
118
  this.config = environments[env];
119
+ const newConfig = this.get();
120
+ this.observers.forEach((observer) => observer.onConfigUpdate(newConfig));
106
121
  }
107
122
  validateAndGetConfig(env) {
108
123
  if (!environments[env]) {
@@ -134,12 +149,19 @@ var config = new Config();
134
149
  // src/config/sdk.ts
135
150
  var SDK = class {
136
151
  /**
137
- * Initialize the SDK with a specific environment
152
+ * Change the environment after initialization
138
153
  * @param env The environment to use ('dev' or 'production')
139
154
  */
140
155
  setEnvironment(env) {
141
156
  config.setEnvironment(env);
142
157
  }
158
+ /**
159
+ * Get the current environment configuration
160
+ * @returns The current environment configuration
161
+ */
162
+ getConfig() {
163
+ return config.get();
164
+ }
143
165
  };
144
166
  var sdk = new SDK();
145
167
 
@@ -3480,6 +3502,15 @@ var RouterService = class {
3480
3502
  constructor() {
3481
3503
  this.provider = new import_ethers5.JsonRpcProvider(config.getRpcUrl());
3482
3504
  this.contract = Router__factory.connect(config.getRouterAddress(), this.provider);
3505
+ config.registerObserver(this);
3506
+ }
3507
+ /**
3508
+ * Implementation of ConfigObserver interface
3509
+ * Updates service when config changes
3510
+ */
3511
+ onConfigUpdate(newConfig) {
3512
+ this.provider = new import_ethers5.JsonRpcProvider(newConfig.rpcUrl);
3513
+ this.contract = Router__factory.connect(newConfig.routerAddress, this.provider);
3483
3514
  }
3484
3515
  async getSigner() {
3485
3516
  return await this.contract.SIGNER();
@@ -3559,6 +3590,14 @@ var SignerService = class {
3559
3590
  constructor() {
3560
3591
  this.routerService = routerService;
3561
3592
  this.provider = new import_ethers6.JsonRpcProvider(config.getRpcUrl());
3593
+ config.registerObserver(this);
3594
+ }
3595
+ /**
3596
+ * Implementation of ConfigObserver interface
3597
+ * Updates service when config changes
3598
+ */
3599
+ onConfigUpdate(newConfig) {
3600
+ this.provider = new import_ethers6.JsonRpcProvider(newConfig.rpcUrl);
3562
3601
  }
3563
3602
  async getDomain() {
3564
3603
  const signerAddress = await this.routerService.getSigner();
@@ -3637,6 +3676,14 @@ var SubmitSettlementResponseSchema = import_zod.z.object({
3637
3676
  var SolverService = class {
3638
3677
  constructor() {
3639
3678
  this.baseURL = config.getBackendUrl();
3679
+ config.registerObserver(this);
3680
+ }
3681
+ /**
3682
+ * Implementation of ConfigObserver interface
3683
+ * Updates service when config changes
3684
+ */
3685
+ onConfigUpdate(newConfig) {
3686
+ this.baseURL = newConfig.backendUrl;
3640
3687
  }
3641
3688
  /**
3642
3689
  * Submits a settlement transaction to the solver backend
@@ -3702,6 +3749,14 @@ var TokenResponseSchema = import_zod3.z.object({
3702
3749
  var TokenService = class {
3703
3750
  constructor() {
3704
3751
  this.baseURL = config.getBackendUrl();
3752
+ config.registerObserver(this);
3753
+ }
3754
+ /**
3755
+ * Implementation of ConfigObserver interface
3756
+ * Updates service when config changes
3757
+ */
3758
+ onConfigUpdate(newConfig) {
3759
+ this.baseURL = newConfig.backendUrl;
3705
3760
  }
3706
3761
  /**
3707
3762
  * Fetches all available tokens from the API
package/dist/index.mjs CHANGED
@@ -24,10 +24,23 @@ var environments = {
24
24
  }
25
25
  };
26
26
  var Config = class {
27
- constructor() {
28
- this.env = process.env.SDK_ENV || "production";
27
+ constructor(env = "production") {
28
+ this.observers = [];
29
+ this.env = env;
29
30
  this.config = this.validateAndGetConfig(this.env);
30
31
  }
32
+ /**
33
+ * Register a service as an observer to be notified of config changes
34
+ */
35
+ registerObserver(observer) {
36
+ this.observers.push(observer);
37
+ }
38
+ /**
39
+ * Remove a service from observers
40
+ */
41
+ unregisterObserver(observer) {
42
+ this.observers = this.observers.filter((obs) => obs !== observer);
43
+ }
31
44
  /**
32
45
  * Set the environment for the SDK
33
46
  * @param env The environment to use ('dev' or 'production')
@@ -38,6 +51,8 @@ var Config = class {
38
51
  }
39
52
  this.env = env;
40
53
  this.config = environments[env];
54
+ const newConfig = this.get();
55
+ this.observers.forEach((observer) => observer.onConfigUpdate(newConfig));
41
56
  }
42
57
  validateAndGetConfig(env) {
43
58
  if (!environments[env]) {
@@ -69,12 +84,19 @@ var config = new Config();
69
84
  // src/config/sdk.ts
70
85
  var SDK = class {
71
86
  /**
72
- * Initialize the SDK with a specific environment
87
+ * Change the environment after initialization
73
88
  * @param env The environment to use ('dev' or 'production')
74
89
  */
75
90
  setEnvironment(env) {
76
91
  config.setEnvironment(env);
77
92
  }
93
+ /**
94
+ * Get the current environment configuration
95
+ * @returns The current environment configuration
96
+ */
97
+ getConfig() {
98
+ return config.get();
99
+ }
78
100
  };
79
101
  var sdk = new SDK();
80
102
 
@@ -3415,6 +3437,15 @@ var RouterService = class {
3415
3437
  constructor() {
3416
3438
  this.provider = new JsonRpcProvider(config.getRpcUrl());
3417
3439
  this.contract = Router__factory.connect(config.getRouterAddress(), this.provider);
3440
+ config.registerObserver(this);
3441
+ }
3442
+ /**
3443
+ * Implementation of ConfigObserver interface
3444
+ * Updates service when config changes
3445
+ */
3446
+ onConfigUpdate(newConfig) {
3447
+ this.provider = new JsonRpcProvider(newConfig.rpcUrl);
3448
+ this.contract = Router__factory.connect(newConfig.routerAddress, this.provider);
3418
3449
  }
3419
3450
  async getSigner() {
3420
3451
  return await this.contract.SIGNER();
@@ -3494,6 +3525,14 @@ var SignerService = class {
3494
3525
  constructor() {
3495
3526
  this.routerService = routerService;
3496
3527
  this.provider = new JsonRpcProvider2(config.getRpcUrl());
3528
+ config.registerObserver(this);
3529
+ }
3530
+ /**
3531
+ * Implementation of ConfigObserver interface
3532
+ * Updates service when config changes
3533
+ */
3534
+ onConfigUpdate(newConfig) {
3535
+ this.provider = new JsonRpcProvider2(newConfig.rpcUrl);
3497
3536
  }
3498
3537
  async getDomain() {
3499
3538
  const signerAddress = await this.routerService.getSigner();
@@ -3572,6 +3611,14 @@ var SubmitSettlementResponseSchema = z.object({
3572
3611
  var SolverService = class {
3573
3612
  constructor() {
3574
3613
  this.baseURL = config.getBackendUrl();
3614
+ config.registerObserver(this);
3615
+ }
3616
+ /**
3617
+ * Implementation of ConfigObserver interface
3618
+ * Updates service when config changes
3619
+ */
3620
+ onConfigUpdate(newConfig) {
3621
+ this.baseURL = newConfig.backendUrl;
3575
3622
  }
3576
3623
  /**
3577
3624
  * Submits a settlement transaction to the solver backend
@@ -3637,6 +3684,14 @@ var TokenResponseSchema = z3.object({
3637
3684
  var TokenService = class {
3638
3685
  constructor() {
3639
3686
  this.baseURL = config.getBackendUrl();
3687
+ config.registerObserver(this);
3688
+ }
3689
+ /**
3690
+ * Implementation of ConfigObserver interface
3691
+ * Updates service when config changes
3692
+ */
3693
+ onConfigUpdate(newConfig) {
3694
+ this.baseURL = newConfig.backendUrl;
3640
3695
  }
3641
3696
  /**
3642
3697
  * Fetches all available tokens from the API
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimex-xyz/market-maker-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -42,7 +42,7 @@
42
42
  "commit": "cz"
43
43
  },
44
44
  "dependencies": {
45
- "axios": "^1.7.9",
45
+ "axios": "^1.8.2",
46
46
  "bip174": "^3.0.0-rc.1",
47
47
  "bitcoinjs-lib": "^7.0.0-rc.0",
48
48
  "ecpair": "^3.0.0-rc.0",