@optimex-xyz/market-maker-sdk 0.8.0 → 0.8.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.
Files changed (2) hide show
  1. package/README.md +148 -14
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,11 +1,12 @@
1
1
  # PMM API Integration Documentation
2
2
 
3
- > **CHANGELOG (v0.7.1)**:
3
+ > **CHANGELOG (v0.8.0)**:
4
4
  > - **Breaking Changes:**
5
- > - Environment key `dev` has been renamed to `staging` - please update your environment configuration accordingly
6
- > - Several functions from `routerService` moved to `protocolService`
5
+ > - Update to get router contract from protocol fetcher
6
+ > - Use consistent trade_id across all protocol
7
+ > - Add `user_receiving_address`, `user_refund_pubkey`, `from_user_address` to `indicative_quote` api requirement as optional fields.
7
8
  > - **Upgrade Notes:**
8
- > - For PMMs using version 6.2, you can update to v0.7.1 without needing to change anything
9
+ > - For PMMs older version you can update to v0.8.0 without needing to change anything
9
10
  > - If you need to use the Router, please use the values provided in the environment configuration section
10
11
 
11
12
  > **Note**: If you prefer using the SDK instead of direct API integration, please refer to the [PMM SDK Integration Guide](sdk-integration.md).
@@ -18,11 +19,12 @@ A comprehensive guide for implementing Private Market Makers (PMMs) in the cross
18
19
  - [1. Overview](#1-overview)
19
20
  - [2. Quick Start](#2-quick-start)
20
21
  - [3. PMM Backend APIs](#3-pmm-backend-apis)
21
- - [3.1. Endpoint: `/indicative-quote`](#31-endpoint-indicative-quote)
22
- - [3.2. Endpoint: `/commitment-quote`](#32-endpoint-commitment-quote)
23
- - [3.3. Endpoint: `/settlement-signature`](#33-endpoint-settlement-signature)
24
- - [3.4. Endpoint: `/ack-settlement`](#34-endpoint-ack-settlement)
25
- - [3.5. Endpoint: `/signal-payment`](#35-endpoint-signal-payment)
22
+ - [3.1. Endpoint: `/indicative-quote`](#31-endpoint-indicative-quote)
23
+ - [3.2. Endpoint: `/commitment-quote`](#32-endpoint-commitment-quote)
24
+ - [3.3. Endpoint: `/liquidation-quote`](#33-endpoint-liquidation-quote)
25
+ - [3.4. Endpoint: `/settlement-signature`](#34-endpoint-settlement-signature)
26
+ - [3.5. Endpoint: `/ack-settlement`](#35-endpoint-ack-settlement)
27
+ - [3.6. Endpoint: `/signal-payment`](#36-endpoint-signal-payment)
26
28
  - [4. Solver API Endpoints for PMMs](#4-solver-api-endpoints-for-pmms)
27
29
  - [4.1. Endpoint: `/v1/market-maker/tokens`](#41-endpoint-v1market-makertokens)
28
30
  - [4.2. Endpoint: `/v1/market-maker/submit-settlement-tx`](#42-endpoint-v1market-makersubmit-settlement-tx)
@@ -88,7 +90,7 @@ sequenceDiagram
88
90
 
89
91
  **Optimex L2 Testnet**
90
92
  - **Signer**: [0xA89F5060B810F3b6027D7663880c43ee77A865C7](https://scan-testnet.optimex.xyz/address/0xA89F5060B810F3b6027D7663880c43ee77A865C7)
91
- - **Router**: [0xa6E13A3c6c63C64d45bB453E0402B7D2eE53E564](https://scan-testnet.optimex.xyz/address/0xa6E13A3c6c63C64d45bB453E0402B7D2eE53E564)
93
+ - **Router**: [0x31C88ebd9E430455487b6a5c8971e8eF63e97ED4](https://scan-testnet.optimex.xyz/address/0x31C88ebd9E430455487b6a5c8971e8eF63e97ED4)
92
94
  - **ProtocolFetcherProxy**: [0x7c07151ca4DFd93F352Ab9B132A95866697c38c2](https://scan-testnet.optimex.xyz/address/0x7c07151ca4DFd93F352Ab9B132A95866697c38c2)
93
95
 
94
96
  **Ethereum Sepolia**
@@ -106,7 +108,7 @@ sequenceDiagram
106
108
 
107
109
  **Optimex L2 Mainnet**
108
110
  - **Signer**: [0xCF9786F123F1071023dB8049808C223e94c384be](https://scan.optimex.xyz/address/0xCF9786F123F1071023dB8049808C223e94c384be)
109
- - **Router**: [0xF7fedF4A250157010807E6eA60258E3B768149Ff](https://scan.optimex.xyz/address/0xF7fedF4A250157010807E6eA60258E3B768149Ff)
111
+ - **Router**: [0x1e878cCa765a8aAFEBecCa672c767441b4859634](https://scan.optimex.xyz/address/0x1e878cCa765a8aAFEBecCa672c767441b4859634)
110
112
  - **ProtocolFetcherProxy**: [0xFDEd4CEf9aE1E03D0BeF161262a266c1c157a32b](https://scan.optimex.xyz/address/0xFDEd4CEf9aE1E03D0BeF161262a266c1c157a32b)
111
113
 
112
114
  **Ethereum Mainnet**
@@ -141,6 +143,9 @@ Provides an indicative quote for the given token pair and trade amount. The quot
141
143
  - `deposited` (boolean, optional): Whether the deposit has been confirmed. This allows the PMM to decide the returned quote.
142
144
  - `trade_timeout` (string, optional): The deadline when user is expected to receive tokens from PMM in UNIX timestamp. We expect the trade to be completed before this timeout. But if not, some actions can still be taken.
143
145
  - `script_timeout` (string, optional): The hard timeout for the trade, UNIX timestamp. After this timeout, the trade will not be processed further.
146
+ - `from_user_address` (string, optional): The user's address from which the input token will be sent from.
147
+ - `user_receiving_address` (string, optional): The user's address to which the output token will be sent to.
148
+ - `user_refund_pubkey` (string, optional): The user's public key to which the refund will be sent.
144
149
 
145
150
  #### Example Request
146
151
 
@@ -349,7 +354,136 @@ async function getCommitmentQuote(req, res) {
349
354
  ```
350
355
  </details>
351
356
 
352
- ### 3.3. Endpoint: `/settlement-signature`
357
+ ### 3.3. Endpoint: `/liquidation-quote`
358
+
359
+ #### Description
360
+
361
+ Provides a firm commitment quote for a liquidation trade. This endpoint is called after the user deposits funds and represents a binding commitment to execute the liquidation at the quoted rate.
362
+
363
+ #### Request Parameters
364
+
365
+ - **HTTP Method**: `GET`
366
+ - **Query Parameters**:
367
+ - `session_id` (string): Session identifier from the indicative quote.
368
+ - `trade_id` (string): Unique trade identifier.
369
+ - `from_token_id` (string): The ID of the source token.
370
+ - `to_token_id` (string): The ID of the destination token.
371
+ - `amount` (string): The amount of the source token to be traded, in base 10. This should be treated as a BigInt in your implementation.
372
+ - `payment_metadata` (string, optional): Hex string encoded data for smart contract payment method.
373
+ - `from_user_address` (string): The user's address from which the input token will be sent.
374
+ - `to_user_address` (string): The user's address to which the output token will be sent.
375
+ - `user_deposit_tx` (string): Transaction hash of user's deposit.
376
+ - `user_deposit_vault` (string): Vault containing user's deposit.
377
+ - `trade_deadline` (string): Expected payment deadline (UNIX timestamp).
378
+ - `script_deadline` (string): Withdrawal deadline if unpaid (UNIX timestamp).
379
+
380
+ #### Example Request
381
+
382
+ ```
383
+ GET /liquidation-quote?session_id=12345&trade_id=0x3bfe2fc4889a98a39b31b348e7b212ea3f2bea63fd1ea2e0c8ba326433677328&from_token_id=ETH&to_token_id=BTC&amount=1000000000000000000&from_user_address=0xUserAddress&to_user_address=bc1p68q6hew27ljf4ghvlnwqz0fq32qg7tsgc7jr5levfy8r74p5k52qqphk07&user_deposit_tx=0xDepositTxHash&user_deposit_vault=VaultData&trade_deadline=1696012800&script_deadline=1696016400
384
+ ```
385
+
386
+ #### Expected Response
387
+
388
+ - **HTTP Status**: `200 OK`
389
+ - **Response Body** (JSON):
390
+
391
+ ```json
392
+ {
393
+ "trade_id": "0x3bfe2fc4889a98a39b31b348e7b212ea3f2bea63fd1ea2e0c8ba326433677328",
394
+ "liquidation_quote": "987654321000000000",
395
+ "error": ""
396
+ }
397
+ ```
398
+
399
+ - `trade_id` (string): The trade ID associated with the request.
400
+ - `liquidation_quote` (string): **Firm committed quote** - PMM must honor this price. Should be treated as a BigInt in your implementation.
401
+ - `error` (string): Error message, if any (empty if no error).
402
+
403
+ <details>
404
+ <summary><strong>Example Implementation</strong></summary>
405
+
406
+ ```js
407
+ async function getLiquidationQuote(req, res) {
408
+ try {
409
+ const {
410
+ session_id,
411
+ trade_id,
412
+ from_token_id,
413
+ to_token_id,
414
+ amount,
415
+ from_user_address,
416
+ to_user_address,
417
+ user_deposit_tx,
418
+ user_deposit_vault,
419
+ trade_deadline,
420
+ script_deadline
421
+ } = req.query;
422
+
423
+ // Validate the session exists
424
+ const session = await sessionRepository.findById(session_id);
425
+ if (!session) {
426
+ return res.status(400).json({
427
+ trade_id,
428
+ liquidation_quote: '0',
429
+ error: 'Session not found'
430
+ });
431
+ }
432
+
433
+ // Fetch token information from Solver API
434
+ const tokensResponse = await fetch('https://api.solver.example/v1/market-maker/tokens');
435
+ const tokensData = await tokensResponse.json();
436
+
437
+ // Find the from token and to token
438
+ const fromToken = tokensData.data.tokens.find(token => token.token_id === from_token_id);
439
+ const toToken = tokensData.data.tokens.find(token => token.token_id === to_token_id);
440
+
441
+ if (!fromToken || !toToken) {
442
+ return res.status(400).json({
443
+ trade_id,
444
+ liquidation_quote: '0',
445
+ error: 'Token not found'
446
+ });
447
+ }
448
+
449
+ // Calculate the firm liquidation quote (implementation specific to your PMM)
450
+ // Note: Treat numeric values as BigInt
451
+ const amountBigInt = BigInt(amount);
452
+ const quote = calculateLiquidationQuote(fromToken, toToken, amountBigInt, trade_deadline);
453
+
454
+ // Store the trade in the database
455
+ await tradeRepository.create({
456
+ tradeId: trade_id,
457
+ sessionId: session_id,
458
+ fromTokenId: from_token_id,
459
+ toTokenId: to_token_id,
460
+ amount: amountBigInt.toString(),
461
+ fromUserAddress: from_user_address,
462
+ toUserAddress: to_user_address,
463
+ userDepositTx: user_deposit_tx,
464
+ userDepositVault: user_deposit_vault,
465
+ tradeDeadline: trade_deadline,
466
+ scriptDeadline: script_deadline,
467
+ liquidationQuote: quote.toString()
468
+ });
469
+
470
+ return res.status(200).json({
471
+ trade_id,
472
+ liquidation_quote: quote.toString(),
473
+ error: ''
474
+ });
475
+ } catch (error) {
476
+ return res.status(500).json({
477
+ trade_id: req.query.trade_id || '',
478
+ liquidation_quote: '0',
479
+ error: error.message
480
+ });
481
+ }
482
+ }
483
+ ```
484
+ </details>
485
+
486
+ ### 3.4. Endpoint: `/settlement-signature`
353
487
 
354
488
  #### Description
355
489
 
@@ -455,7 +589,7 @@ async function getSettlementSignature(req, res) {
455
589
  ```
456
590
  </details>
457
591
 
458
- ### 3.4. Endpoint: `/ack-settlement`
592
+ ### 3.5. Endpoint: `/ack-settlement`
459
593
 
460
594
  #### Description
461
595
 
@@ -537,7 +671,7 @@ async function ackSettlement(req, res) {
537
671
  ```
538
672
  </details>
539
673
 
540
- ### 3.5. Endpoint: `/signal-payment`
674
+ ### 3.6. Endpoint: `/signal-payment`
541
675
 
542
676
  #### Description
543
677
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimex-xyz/market-maker-sdk",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"