@0xmonaco/core 0.8.22 → 1.0.3

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.
@@ -71,7 +71,7 @@ export declare class AuthAPIImpl extends BaseAPI implements AuthAPI {
71
71
  * console.log(`User ID: ${authResult.user.id}`);
72
72
  * ```
73
73
  */
74
- authenticate(clientId: string): Promise<AuthState>;
74
+ authenticate(clientId: string, referralCode?: string): Promise<AuthState>;
75
75
  /**
76
76
  * Signs a challenge message using the wallet client.
77
77
  *
@@ -137,7 +137,7 @@ export declare class AuthAPIImpl extends BaseAPI implements AuthAPI {
137
137
  * console.log(`Session public key: ${authResult.sessionPublicKey}`);
138
138
  * ```
139
139
  */
140
- verifySignature(address: string, signature: string, nonce: string, clientId: string, session: SessionCredentials): Promise<AuthState>;
140
+ verifySignature(address: string, signature: string, nonce: string, clientId: string, session: SessionCredentials, referralCode?: string): Promise<AuthState>;
141
141
  /**
142
142
  * Extends the current session's expiry.
143
143
  *
@@ -77,7 +77,7 @@ export class AuthAPIImpl extends BaseAPI {
77
77
  * console.log(`User ID: ${authResult.user.id}`);
78
78
  * ```
79
79
  */
80
- async authenticate(clientId) {
80
+ async authenticate(clientId, referralCode) {
81
81
  if (!this.walletClient) {
82
82
  throw new InvalidConfigError("Wallet client not set. Connect a wallet first.", "walletClient");
83
83
  }
@@ -96,8 +96,8 @@ export class AuthAPIImpl extends BaseAPI {
96
96
  const challenge = await this.createChallenge(account.address, clientId, session.publicKey);
97
97
  // 3. Sign the challenge message with the wallet
98
98
  const signature = await this.signChallenge(challenge.message);
99
- // 4. Verify signature, registering the session public key
100
- return await this.verifySignature(account.address, signature, challenge.nonce, clientId, session);
99
+ // 4. Verify signature, registering the session public key (and optional referral)
100
+ return await this.verifySignature(account.address, signature, challenge.nonce, clientId, session, referralCode);
101
101
  }
102
102
  /**
103
103
  * Signs a challenge message using the wallet client.
@@ -192,7 +192,7 @@ export class AuthAPIImpl extends BaseAPI {
192
192
  * console.log(`Session public key: ${authResult.sessionPublicKey}`);
193
193
  * ```
194
194
  */
195
- async verifySignature(address, signature, nonce, clientId, session) {
195
+ async verifySignature(address, signature, nonce, clientId, session, referralCode) {
196
196
  const responseBody = await this.makePublicRequest("/api/v1/auth/verify", {
197
197
  method: "POST",
198
198
  body: JSON.stringify({
@@ -202,6 +202,7 @@ export class AuthAPIImpl extends BaseAPI {
202
202
  clientId: clientId,
203
203
  chainId: this.chain.id,
204
204
  sessionPublicKey: session.publicKey,
205
+ ...(referralCode ? { referralCode } : {}),
205
206
  }),
206
207
  });
207
208
  return {
@@ -12,6 +12,7 @@ export * from "./margin-accounts";
12
12
  export * from "./market";
13
13
  export * from "./orderbook";
14
14
  export * from "./perp";
15
+ export * from "./pitpass";
15
16
  export * from "./positions";
16
17
  export * from "./profile";
17
18
  export * from "./sub-accounts";
package/dist/api/index.js CHANGED
@@ -12,6 +12,7 @@ export * from "./margin-accounts";
12
12
  export * from "./market";
13
13
  export * from "./orderbook";
14
14
  export * from "./perp";
15
+ export * from "./pitpass";
15
16
  export * from "./positions";
16
17
  export * from "./profile";
17
18
  export * from "./sub-accounts";
@@ -167,6 +167,7 @@ export declare const perpRoutes: {
167
167
  tradingPairId?: string;
168
168
  page?: number;
169
169
  pageSize?: number;
170
+ reductionOnly?: boolean;
170
171
  }) => string;
171
172
  readonly pnlHistory: (positionId: string, params: {
172
173
  interval: string;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * PitPass TraderCode API Implementation
3
+ *
4
+ * Provides methods for the PitPass referral system: reading your wallet-derived
5
+ * TraderCode, a public lookup to validate a referral code at sign-up, reading
6
+ * your accrued rewards balance, and transferring rewards into a tradeable balance.
7
+ *
8
+ * `getMyTraderCode` and `getRewardsBalance` require authentication.
9
+ * `getTraderCodeInfo` is public (no auth required).
10
+ * `transferRewards` requires authentication.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * // Read your own code (authenticated)
15
+ * const { code } = await sdk.pitpass.getMyTraderCode();
16
+ * console.log(`Share code: Monaco - ${code}`);
17
+ *
18
+ * // Validate a referral code at sign-up (public)
19
+ * const info = await sdk.pitpass.getTraderCodeInfo("0xabc...");
20
+ * console.log(`Referrer code: ${info.code}`);
21
+ *
22
+ * // Read accrued rewards balance (authenticated)
23
+ * const { balances } = await sdk.pitpass.getRewardsBalance();
24
+ * for (const b of balances) {
25
+ * console.log(`${b.token}: ${b.available}`);
26
+ * }
27
+ *
28
+ * // Transfer rewards into trading balance (authenticated)
29
+ * const result = await sdk.pitpass.transferRewards({
30
+ * token: "0xusdc...",
31
+ * amount: "1000000",
32
+ * });
33
+ * console.log(`Rewards remaining: ${result.rewardsBalance}`);
34
+ * ```
35
+ */
36
+ import type { GetRewardsBalanceResponse, PitpassAPI, TraderCodeInfoResponse, TraderCodeResponse, TransferRewardsParams, TransferRewardsResponse } from "@0xmonaco/types";
37
+ import { BaseAPI } from "../base";
38
+ export declare class PitpassAPIImpl extends BaseAPI implements PitpassAPI {
39
+ /**
40
+ * Return the authenticated caller's TraderCode (their normalized wallet address).
41
+ */
42
+ getMyTraderCode(): Promise<TraderCodeResponse>;
43
+ /**
44
+ * Public lookup of a TraderCode by wallet address.
45
+ * Accepts the bare address or the `Monaco - <address>` display form.
46
+ */
47
+ getTraderCodeInfo(code: string): Promise<TraderCodeInfoResponse>;
48
+ /**
49
+ * Return the caller's current PitPass rewards-bucket balances.
50
+ */
51
+ getRewardsBalance(): Promise<GetRewardsBalanceResponse>;
52
+ /**
53
+ * Transfer earned PitPass rewards into a trading balance.
54
+ */
55
+ transferRewards(params: TransferRewardsParams): Promise<TransferRewardsResponse>;
56
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * PitPass TraderCode API Implementation
3
+ *
4
+ * Provides methods for the PitPass referral system: reading your wallet-derived
5
+ * TraderCode, a public lookup to validate a referral code at sign-up, reading
6
+ * your accrued rewards balance, and transferring rewards into a tradeable balance.
7
+ *
8
+ * `getMyTraderCode` and `getRewardsBalance` require authentication.
9
+ * `getTraderCodeInfo` is public (no auth required).
10
+ * `transferRewards` requires authentication.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * // Read your own code (authenticated)
15
+ * const { code } = await sdk.pitpass.getMyTraderCode();
16
+ * console.log(`Share code: Monaco - ${code}`);
17
+ *
18
+ * // Validate a referral code at sign-up (public)
19
+ * const info = await sdk.pitpass.getTraderCodeInfo("0xabc...");
20
+ * console.log(`Referrer code: ${info.code}`);
21
+ *
22
+ * // Read accrued rewards balance (authenticated)
23
+ * const { balances } = await sdk.pitpass.getRewardsBalance();
24
+ * for (const b of balances) {
25
+ * console.log(`${b.token}: ${b.available}`);
26
+ * }
27
+ *
28
+ * // Transfer rewards into trading balance (authenticated)
29
+ * const result = await sdk.pitpass.transferRewards({
30
+ * token: "0xusdc...",
31
+ * amount: "1000000",
32
+ * });
33
+ * console.log(`Rewards remaining: ${result.rewardsBalance}`);
34
+ * ```
35
+ */
36
+ import { TransferRewardsParamsSchema, validate } from "@0xmonaco/types";
37
+ import { BaseAPI } from "../base";
38
+ export class PitpassAPIImpl extends BaseAPI {
39
+ /**
40
+ * Return the authenticated caller's TraderCode (their normalized wallet address).
41
+ */
42
+ async getMyTraderCode() {
43
+ return await this.makeAuthenticatedRequest("/api/v1/pitpass/codes/me", { method: "GET" });
44
+ }
45
+ /**
46
+ * Public lookup of a TraderCode by wallet address.
47
+ * Accepts the bare address or the `Monaco - <address>` display form.
48
+ */
49
+ async getTraderCodeInfo(code) {
50
+ const encoded = encodeURIComponent(code.trim());
51
+ return await this.makePublicRequest(`/api/v1/pitpass/codes/${encoded}`, { method: "GET" });
52
+ }
53
+ /**
54
+ * Return the caller's current PitPass rewards-bucket balances.
55
+ */
56
+ async getRewardsBalance() {
57
+ return await this.makeAuthenticatedRequest("/api/v1/pitpass/rewards/balance", { method: "GET" });
58
+ }
59
+ /**
60
+ * Transfer earned PitPass rewards into a trading balance.
61
+ */
62
+ async transferRewards(params) {
63
+ const validated = validate(TransferRewardsParamsSchema, params);
64
+ return await this.makeAuthenticatedRequest("/api/v1/pitpass/rewards/transfer", {
65
+ method: "POST",
66
+ body: JSON.stringify({ token: validated.token, amount: validated.amount }),
67
+ });
68
+ }
69
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * PitPass API Module
3
+ *
4
+ * Exports the PitPass TraderCode API implementation.
5
+ */
6
+ export { PitpassAPIImpl } from "./api";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * PitPass API Module
3
+ *
4
+ * Exports the PitPass TraderCode API implementation.
5
+ */
6
+ export { PitpassAPIImpl } from "./api";
@@ -211,12 +211,16 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
211
211
  *
212
212
  * @param assetId - The asset identifier (UUID) to withdraw
213
213
  * @param amount - The raw token amount to withdraw (as bigint)
214
- * @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
214
+ * @param autoWait - When `true` (default) polls for the merkle-proof calldata
215
+ * and submits the on-chain `executeWithdrawal` transaction, then waits for
216
+ * confirmation. When `false`, returns `{ withdrawalIndex, status: "awaiting_proof" }`
217
+ * immediately after the POST — skipping both the calldata poll and the
218
+ * on-chain submission. Use `retryWithdrawal(withdrawalIndex)` to finish later.
215
219
  * @param sourceOrRetry - Source ledger (`"spot"` or `"margin"`) or legacy retry options
216
220
  * @param retry - Polling cadence/timeout while waiting for the proof when a source is supplied
217
221
  * @returns Promise resolving to a [`WithdrawResult`]: on success the submitted
218
- * transaction plus `withdrawalIndex`; on poll-timeout `{ withdrawalIndex,
219
- * status: "awaiting_proof" }`.
222
+ * transaction plus `withdrawalIndex`; on poll-timeout or `autoWait=false`
223
+ * returns `{ withdrawalIndex, status: "awaiting_proof" }`.
220
224
  * @throws {APIError} When the asset is not found or the initiate request is rejected
221
225
  * @throws {ContractError} When the on-chain submission fails
222
226
  * @throws {InvalidConfigError} When wallet account is not available
@@ -382,12 +382,16 @@ export class VaultAPIImpl extends BaseAPI {
382
382
  *
383
383
  * @param assetId - The asset identifier (UUID) to withdraw
384
384
  * @param amount - The raw token amount to withdraw (as bigint)
385
- * @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
385
+ * @param autoWait - When `true` (default) polls for the merkle-proof calldata
386
+ * and submits the on-chain `executeWithdrawal` transaction, then waits for
387
+ * confirmation. When `false`, returns `{ withdrawalIndex, status: "awaiting_proof" }`
388
+ * immediately after the POST — skipping both the calldata poll and the
389
+ * on-chain submission. Use `retryWithdrawal(withdrawalIndex)` to finish later.
386
390
  * @param sourceOrRetry - Source ledger (`"spot"` or `"margin"`) or legacy retry options
387
391
  * @param retry - Polling cadence/timeout while waiting for the proof when a source is supplied
388
392
  * @returns Promise resolving to a [`WithdrawResult`]: on success the submitted
389
- * transaction plus `withdrawalIndex`; on poll-timeout `{ withdrawalIndex,
390
- * status: "awaiting_proof" }`.
393
+ * transaction plus `withdrawalIndex`; on poll-timeout or `autoWait=false`
394
+ * returns `{ withdrawalIndex, status: "awaiting_proof" }`.
391
395
  * @throws {APIError} When the asset is not found or the initiate request is rejected
392
396
  * @throws {ContractError} When the on-chain submission fails
393
397
  * @throws {InvalidConfigError} When wallet account is not available
@@ -440,7 +444,14 @@ export class VaultAPIImpl extends BaseAPI {
440
444
  source,
441
445
  }),
442
446
  });
443
- // 2. Poll for the executeWithdrawal calldata until the proof is confirmed.
447
+ // 2. When autoWait=false the caller wants the index immediately so it can
448
+ // finish on-chain later via retryWithdrawal(index). Skip the calldata poll
449
+ // entirely — the proof never lands this early, and the 5-minute default
450
+ // would block the wallet prompt indefinitely (the MACH1 bug).
451
+ if (!autoWait) {
452
+ return { withdrawalIndex, status: "awaiting_proof" };
453
+ }
454
+ // 3. Poll for the executeWithdrawal calldata until the proof is confirmed.
444
455
  // The vault address comes back with it, keeping calldata + target contract
445
456
  // in lockstep.
446
457
  const poll = await this.pollWithdrawalCalldata(withdrawalIndex, retryOptions);
@@ -29,6 +29,9 @@ export declare const COVERED: {
29
29
  get_market_metadata: string;
30
30
  get_market_stats: string;
31
31
  get_my_fee_tier: string;
32
+ get_my_trader_code: string;
33
+ get_rewards_balance: string;
34
+ get_trader_code_info: string;
32
35
  get_open_interest: string;
33
36
  get_order_by_id: string;
34
37
  get_orderbook_snapshot: string;
@@ -85,6 +88,7 @@ export declare const COVERED: {
85
88
  transfer_collateral_to_margin_account: string;
86
89
  transfer_collateral_to_parent_margin_account: string;
87
90
  transfer_collateral_to_risk_bucket: string;
91
+ transfer_rewards: string;
88
92
  update_sub_account_limit: string;
89
93
  upsert_delegated_agent: string;
90
94
  verify_signature: string;
package/dist/coverage.js CHANGED
@@ -29,6 +29,9 @@ export const COVERED = {
29
29
  get_market_metadata: "getMarketMetadata",
30
30
  get_market_stats: "getMarketStats",
31
31
  get_my_fee_tier: "getMyFeeTier",
32
+ get_my_trader_code: "pitpass.getMyTraderCode",
33
+ get_rewards_balance: "pitpass.getRewardsBalance",
34
+ get_trader_code_info: "pitpass.getTraderCodeInfo",
32
35
  get_open_interest: "getOpenInterest",
33
36
  get_order_by_id: "getOrder",
34
37
  get_orderbook_snapshot: "getOrderbook",
@@ -85,6 +88,7 @@ export const COVERED = {
85
88
  transfer_collateral_to_margin_account: "transferCollateralToMarginAccount",
86
89
  transfer_collateral_to_parent_margin_account: "transferCollateralToParentMarginAccount",
87
90
  transfer_collateral_to_risk_bucket: "transferCollateralToRiskBucket",
91
+ transfer_rewards: "pitpass.transferRewards",
88
92
  update_sub_account_limit: "subAccounts.updateLimit",
89
93
  upsert_delegated_agent: "upsertDelegatedAgent",
90
94
  verify_signature: "verifySignature",
package/dist/sdk.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ApplicationsAPI, AuthAPI, AuthState, DelegatedAgentsAPI, FaucetAPI, FeesAPI, MarginAccountsAPI, MarketAPI, MonacoSDK, Network, PositionsAPI, ProfileAPI, SDKConfig, SubAccountsAPI, TradingAPI, VaultAPI, WhitelistAPI, WithdrawalsAPI } from "@0xmonaco/types";
1
+ import type { ApplicationsAPI, AuthAPI, AuthState, DelegatedAgentsAPI, FaucetAPI, FeesAPI, MarginAccountsAPI, MarketAPI, MonacoSDK, Network, PitpassAPI, PositionsAPI, ProfileAPI, SDKConfig, SubAccountsAPI, TradingAPI, VaultAPI, WhitelistAPI, WithdrawalsAPI } from "@0xmonaco/types";
2
2
  import { type Address, type PublicClient, type TransactionReceipt, type WalletClient } from "viem";
3
3
  import { type MonacoWebSocket, OrderbookAPIImpl, TradesAPIImpl } from "./api";
4
4
  export declare class MonacoSDKImpl implements MonacoSDK {
@@ -6,6 +6,7 @@ export declare class MonacoSDKImpl implements MonacoSDK {
6
6
  delegatedAgents: DelegatedAgentsAPI;
7
7
  applications: ApplicationsAPI;
8
8
  fees: FeesAPI;
9
+ pitpass: PitpassAPI;
9
10
  vault: VaultAPI;
10
11
  withdrawals: WithdrawalsAPI;
11
12
  trading: TradingAPI;
package/dist/sdk.js CHANGED
@@ -8,6 +8,7 @@ import { FaucetAPIImpl } from "./api/faucet";
8
8
  import { FeesAPIImpl } from "./api/fees";
9
9
  import { MarginAccountsAPIImpl } from "./api/margin-accounts";
10
10
  import { MarketAPIImpl } from "./api/market";
11
+ import { PitpassAPIImpl } from "./api/pitpass";
11
12
  import { PositionsAPIImpl } from "./api/positions";
12
13
  import { ProfileAPIImpl } from "./api/profile";
13
14
  import { SubAccountsAPIImpl } from "./api/sub-accounts";
@@ -33,6 +34,7 @@ export class MonacoSDKImpl {
33
34
  delegatedAgents;
34
35
  applications;
35
36
  fees;
37
+ pitpass;
36
38
  vault;
37
39
  withdrawals;
38
40
  trading;
@@ -60,6 +62,7 @@ export class MonacoSDKImpl {
60
62
  this.delegatedAgents.setSessionKeypair(credentials);
61
63
  this.applications.setSessionKeypair(credentials);
62
64
  this.fees.setSessionKeypair(credentials);
65
+ this.pitpass.setSessionKeypair(credentials);
63
66
  this.vault.setSessionKeypair(credentials);
64
67
  this.withdrawals.setSessionKeypair(credentials);
65
68
  this.trading.setSessionKeypair(credentials);
@@ -96,6 +99,7 @@ export class MonacoSDKImpl {
96
99
  this.delegatedAgents.setServerKey(serverKey);
97
100
  this.applications.setServerKey(serverKey);
98
101
  this.fees.setServerKey(serverKey);
102
+ this.pitpass.setServerKey(serverKey);
99
103
  this.vault.setServerKey(serverKey);
100
104
  this.withdrawals.setServerKey(serverKey);
101
105
  this.trading.setServerKey(serverKey);
@@ -164,6 +168,7 @@ export class MonacoSDKImpl {
164
168
  this.auth = new AuthAPIImpl(this.walletClient, this.chain, apiUrl);
165
169
  this.delegatedAgents = new DelegatedAgentsAPIImpl(apiUrl);
166
170
  this.fees = new FeesAPIImpl(apiUrl);
171
+ this.pitpass = new PitpassAPIImpl(apiUrl);
167
172
  this.profile = new ProfileAPIImpl(apiUrl);
168
173
  this.vault = new VaultAPIImpl(this.publicClient, this.walletClient, this.chain, this.applications, this.profile, apiUrl);
169
174
  this.withdrawals = new WithdrawalsAPIImpl(apiUrl);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmonaco/core",
3
- "version": "0.8.22",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,8 +23,8 @@
23
23
  "viem": "^2.45.2"
24
24
  },
25
25
  "dependencies": {
26
- "@0xmonaco/contracts": "0.8.22",
27
- "@0xmonaco/types": "0.8.22",
26
+ "@0xmonaco/contracts": "1.0.3",
27
+ "@0xmonaco/types": "1.0.3",
28
28
  "@noble/curves": "^1.9.1",
29
29
  "@noble/hashes": "^1.8.0",
30
30
  "http-status-codes": "^2.3.0"