@p2pdotme/sdk 1.1.8 → 1.1.9

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/react.d.cts CHANGED
@@ -112,6 +112,132 @@ interface PublicClientLike {
112
112
  }): Promise<readonly unknown[]>;
113
113
  }
114
114
 
115
+ type StakeErrorCode = "VALIDATION_ERROR" | "CONTRACT_READ_ERROR" | "TX_SUBMISSION_FAILED" | "RECEIPT_TIMEOUT" | "TX_REVERTED";
116
+ declare class StakeError extends SdkError<StakeErrorCode> {
117
+ constructor(message: string, options: {
118
+ code: StakeErrorCode;
119
+ cause?: unknown;
120
+ context?: Record<string, unknown>;
121
+ });
122
+ }
123
+
124
+ declare const ZodGetUserStakeParamsSchema: z.ZodObject<{
125
+ user: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
126
+ }, z.core.$strip>;
127
+ type GetUserStakeParams = z.infer<typeof ZodGetUserStakeParamsSchema>;
128
+ declare const ZodGetStakeBoostConfigParamsSchema: z.ZodObject<{
129
+ currency: z.ZodEnum<{
130
+ IDR: "IDR";
131
+ INR: "INR";
132
+ BRL: "BRL";
133
+ ARS: "ARS";
134
+ MEX: "MEX";
135
+ VEN: "VEN";
136
+ EUR: "EUR";
137
+ NGN: "NGN";
138
+ USD: "USD";
139
+ COP: "COP";
140
+ }>;
141
+ }, z.core.$strip>;
142
+ type GetStakeBoostConfigParams = z.infer<typeof ZodGetStakeBoostConfigParamsSchema>;
143
+ declare const ZodGetP2pTokenBalanceParamsSchema: z.ZodObject<{
144
+ address: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
145
+ }, z.core.$strip>;
146
+ type GetP2pTokenBalanceParams = z.infer<typeof ZodGetP2pTokenBalanceParamsSchema>;
147
+ declare const ZodStakeParamsSchema: z.ZodObject<{
148
+ tokens: z.ZodBigInt;
149
+ }, z.core.$strip>;
150
+ type StakeParams = z.infer<typeof ZodStakeParamsSchema>;
151
+ declare const ZodTopUpParamsSchema: z.ZodObject<{
152
+ tokens: z.ZodBigInt;
153
+ }, z.core.$strip>;
154
+ type TopUpParams = z.infer<typeof ZodTopUpParamsSchema>;
155
+
156
+ /**
157
+ * Stake lifecycle state for a user.
158
+ * 0 — None: no active stake.
159
+ * 1 — Active: stake is live.
160
+ * 2 — CooldownRequested: unstake requested; awaiting cooldown end.
161
+ * 3 — Seized: stake was forcefully seized.
162
+ */
163
+ type StakeStatus = "none" | "active" | "cooldown" | "seized";
164
+ /** Normalized on-chain stake record for a user. */
165
+ interface UserStake {
166
+ /** Currently staked token amount (raw bigint, token decimals). */
167
+ readonly stakedAmount: bigint;
168
+ /** Unix seconds when cooldown ends (0 if not in cooldown). */
169
+ readonly cooldownEnd: bigint;
170
+ /** Lifecycle status decoded from the on-chain enum. */
171
+ readonly status: StakeStatus;
172
+ }
173
+ /**
174
+ * Per-currency boost config — how many tokens map to 1 USD of boost, and the
175
+ * cap on USD-denominated boost a stake can unlock.
176
+ */
177
+ interface StakeBoostConfig {
178
+ readonly tokensPerUsdNumerator: bigint;
179
+ readonly tokensPerUsdDenominator: bigint;
180
+ readonly maxBoostUsd: bigint;
181
+ }
182
+ /** Global stake boost configuration shared across all users. */
183
+ interface StakeBoostGlobals {
184
+ readonly p2pToken: Address;
185
+ readonly fraudReserve: Address;
186
+ readonly maxStakeTokens: bigint;
187
+ readonly normalCooldown: bigint;
188
+ readonly blacklistCooldown: bigint;
189
+ readonly tokenDecimals: number;
190
+ readonly totalStaked: bigint;
191
+ }
192
+ interface PreparedTx$1 {
193
+ readonly to: `0x${string}`;
194
+ readonly data: `0x${string}`;
195
+ readonly value: bigint;
196
+ }
197
+ interface TxResult$1 {
198
+ readonly hash: `0x${string}`;
199
+ readonly receipt?: TransactionReceipt;
200
+ }
201
+ interface ExecuteBase$1 {
202
+ readonly walletClient: WalletClient;
203
+ readonly waitForReceipt?: boolean;
204
+ }
205
+
206
+ interface ClaimUnstakeAction {
207
+ prepare(): ResultAsync<PreparedTx$1, StakeError>;
208
+ execute(params: ExecuteBase$1): ResultAsync<TxResult$1, StakeError>;
209
+ }
210
+
211
+ interface RequestUnstakeAction {
212
+ prepare(): ResultAsync<PreparedTx$1, StakeError>;
213
+ execute(params: ExecuteBase$1): ResultAsync<TxResult$1, StakeError>;
214
+ }
215
+
216
+ interface StakeAction {
217
+ prepare(params: StakeParams): ResultAsync<PreparedTx$1, StakeError>;
218
+ execute(params: StakeParams & ExecuteBase$1): ResultAsync<TxResult$1, StakeError>;
219
+ }
220
+
221
+ interface TopUpAction {
222
+ prepare(params: TopUpParams): ResultAsync<PreparedTx$1, StakeError>;
223
+ execute(params: TopUpParams & ExecuteBase$1): ResultAsync<TxResult$1, StakeError>;
224
+ }
225
+
226
+ interface StakeClient {
227
+ /** Reads the on-chain stake record for a user (stakedAmount, cooldownEnd, status). */
228
+ getUserStake(params: GetUserStakeParams): ResultAsync<UserStake, StakeError>;
229
+ /** Reads the per-currency stake boost config (tokens-per-USD, max boost). */
230
+ getStakeBoostConfig(params: GetStakeBoostConfigParams): ResultAsync<StakeBoostConfig, StakeError>;
231
+ /** Reads global stake boost configuration (token addr, cooldowns, totals). */
232
+ getStakeBoostGlobals(): ResultAsync<StakeBoostGlobals, StakeError>;
233
+ /** Reads the P2P token (ERC20) balance for a given address (raw bigint). */
234
+ getP2pTokenBalance(params: GetP2pTokenBalanceParams): ResultAsync<bigint, StakeError>;
235
+ readonly stake: StakeAction;
236
+ readonly topUp: TopUpAction;
237
+ readonly requestUnstake: RequestUnstakeAction;
238
+ readonly claimUnstake: ClaimUnstakeAction;
239
+ }
240
+
115
241
  type OrdersErrorCode = "VALIDATION_ERROR" | "INVALID_ORDER_ID" | "INVALID_GET_ORDERS_PARAMS" | "INVALID_FEE_CONFIG_PARAMS" | "ORDER_NOT_FOUND" | "CONTRACT_READ_FAILED" | "SUBGRAPH_REQUEST_FAILED" | "SUBGRAPH_VALIDATION_FAILED" | "MALFORMED_ORDER" | "CIRCLE_SELECTION_FAILED" | "ENCRYPTION_FAILED" | "RELAY_IDENTITY_CORRUPT" | "RELAY_IDENTITY_STORE_FAILED" | "TX_SUBMISSION_FAILED" | "RECEIPT_TIMEOUT" | "TX_REVERTED" | "EVENT_WATCH_FAILED";
116
242
  declare class OrdersError extends SdkError<OrdersErrorCode> {
117
243
  constructor(message: string, options: {
@@ -686,6 +812,7 @@ interface SdkConfig {
686
812
  readonly subgraphUrl: string;
687
813
  readonly diamondAddress: Address;
688
814
  readonly usdcAddress: Address;
815
+ readonly p2pTokenAddress: Address;
689
816
  readonly reputationManagerAddress?: Address;
690
817
  readonly fraudEngine?: FraudEngineSdkConfig;
691
818
  readonly orders?: OrdersSdkConfig;
@@ -695,6 +822,7 @@ interface Sdk {
695
822
  readonly profile: Profile;
696
823
  readonly prices: Prices;
697
824
  readonly orders: OrdersClient;
825
+ readonly stake: StakeClient;
698
826
  readonly zkkyc?: Zkkyc;
699
827
  readonly fraudEngine?: FraudEngine;
700
828
  }
@@ -724,6 +852,8 @@ declare function useProfile(): Profile;
724
852
  declare function usePrices(): Prices;
725
853
  /** Returns the Orders instance from the nearest SdkProvider. */
726
854
  declare function useOrders(): OrdersClient;
855
+ /** Returns the Stake instance from the nearest SdkProvider. */
856
+ declare function useStake(): StakeClient;
727
857
  /** Returns the Zkkyc instance from the nearest SdkProvider. */
728
858
  declare function useZkkyc(): Zkkyc;
729
859
  /** Returns the FraudEngine instance from the nearest SdkProvider. */
@@ -749,4 +879,4 @@ interface UseFingerprintResult {
749
879
  }
750
880
  declare function useFingerprint(enabled: boolean): UseFingerprintResult;
751
881
 
752
- export { type FraudEngineSdkConfig, type OrdersSdkConfig, type SdkConfig, SdkProvider, useFingerprint, useFraudEngine, useOrders, usePrices, useProfile, useSdk, useWatchOrders, useZkkyc };
882
+ export { type FraudEngineSdkConfig, type OrdersSdkConfig, type SdkConfig, SdkProvider, useFingerprint, useFraudEngine, useOrders, usePrices, useProfile, useSdk, useStake, useWatchOrders, useZkkyc };
package/dist/react.d.ts CHANGED
@@ -112,6 +112,132 @@ interface PublicClientLike {
112
112
  }): Promise<readonly unknown[]>;
113
113
  }
114
114
 
115
+ type StakeErrorCode = "VALIDATION_ERROR" | "CONTRACT_READ_ERROR" | "TX_SUBMISSION_FAILED" | "RECEIPT_TIMEOUT" | "TX_REVERTED";
116
+ declare class StakeError extends SdkError<StakeErrorCode> {
117
+ constructor(message: string, options: {
118
+ code: StakeErrorCode;
119
+ cause?: unknown;
120
+ context?: Record<string, unknown>;
121
+ });
122
+ }
123
+
124
+ declare const ZodGetUserStakeParamsSchema: z.ZodObject<{
125
+ user: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
126
+ }, z.core.$strip>;
127
+ type GetUserStakeParams = z.infer<typeof ZodGetUserStakeParamsSchema>;
128
+ declare const ZodGetStakeBoostConfigParamsSchema: z.ZodObject<{
129
+ currency: z.ZodEnum<{
130
+ IDR: "IDR";
131
+ INR: "INR";
132
+ BRL: "BRL";
133
+ ARS: "ARS";
134
+ MEX: "MEX";
135
+ VEN: "VEN";
136
+ EUR: "EUR";
137
+ NGN: "NGN";
138
+ USD: "USD";
139
+ COP: "COP";
140
+ }>;
141
+ }, z.core.$strip>;
142
+ type GetStakeBoostConfigParams = z.infer<typeof ZodGetStakeBoostConfigParamsSchema>;
143
+ declare const ZodGetP2pTokenBalanceParamsSchema: z.ZodObject<{
144
+ address: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
145
+ }, z.core.$strip>;
146
+ type GetP2pTokenBalanceParams = z.infer<typeof ZodGetP2pTokenBalanceParamsSchema>;
147
+ declare const ZodStakeParamsSchema: z.ZodObject<{
148
+ tokens: z.ZodBigInt;
149
+ }, z.core.$strip>;
150
+ type StakeParams = z.infer<typeof ZodStakeParamsSchema>;
151
+ declare const ZodTopUpParamsSchema: z.ZodObject<{
152
+ tokens: z.ZodBigInt;
153
+ }, z.core.$strip>;
154
+ type TopUpParams = z.infer<typeof ZodTopUpParamsSchema>;
155
+
156
+ /**
157
+ * Stake lifecycle state for a user.
158
+ * 0 — None: no active stake.
159
+ * 1 — Active: stake is live.
160
+ * 2 — CooldownRequested: unstake requested; awaiting cooldown end.
161
+ * 3 — Seized: stake was forcefully seized.
162
+ */
163
+ type StakeStatus = "none" | "active" | "cooldown" | "seized";
164
+ /** Normalized on-chain stake record for a user. */
165
+ interface UserStake {
166
+ /** Currently staked token amount (raw bigint, token decimals). */
167
+ readonly stakedAmount: bigint;
168
+ /** Unix seconds when cooldown ends (0 if not in cooldown). */
169
+ readonly cooldownEnd: bigint;
170
+ /** Lifecycle status decoded from the on-chain enum. */
171
+ readonly status: StakeStatus;
172
+ }
173
+ /**
174
+ * Per-currency boost config — how many tokens map to 1 USD of boost, and the
175
+ * cap on USD-denominated boost a stake can unlock.
176
+ */
177
+ interface StakeBoostConfig {
178
+ readonly tokensPerUsdNumerator: bigint;
179
+ readonly tokensPerUsdDenominator: bigint;
180
+ readonly maxBoostUsd: bigint;
181
+ }
182
+ /** Global stake boost configuration shared across all users. */
183
+ interface StakeBoostGlobals {
184
+ readonly p2pToken: Address;
185
+ readonly fraudReserve: Address;
186
+ readonly maxStakeTokens: bigint;
187
+ readonly normalCooldown: bigint;
188
+ readonly blacklistCooldown: bigint;
189
+ readonly tokenDecimals: number;
190
+ readonly totalStaked: bigint;
191
+ }
192
+ interface PreparedTx$1 {
193
+ readonly to: `0x${string}`;
194
+ readonly data: `0x${string}`;
195
+ readonly value: bigint;
196
+ }
197
+ interface TxResult$1 {
198
+ readonly hash: `0x${string}`;
199
+ readonly receipt?: TransactionReceipt;
200
+ }
201
+ interface ExecuteBase$1 {
202
+ readonly walletClient: WalletClient;
203
+ readonly waitForReceipt?: boolean;
204
+ }
205
+
206
+ interface ClaimUnstakeAction {
207
+ prepare(): ResultAsync<PreparedTx$1, StakeError>;
208
+ execute(params: ExecuteBase$1): ResultAsync<TxResult$1, StakeError>;
209
+ }
210
+
211
+ interface RequestUnstakeAction {
212
+ prepare(): ResultAsync<PreparedTx$1, StakeError>;
213
+ execute(params: ExecuteBase$1): ResultAsync<TxResult$1, StakeError>;
214
+ }
215
+
216
+ interface StakeAction {
217
+ prepare(params: StakeParams): ResultAsync<PreparedTx$1, StakeError>;
218
+ execute(params: StakeParams & ExecuteBase$1): ResultAsync<TxResult$1, StakeError>;
219
+ }
220
+
221
+ interface TopUpAction {
222
+ prepare(params: TopUpParams): ResultAsync<PreparedTx$1, StakeError>;
223
+ execute(params: TopUpParams & ExecuteBase$1): ResultAsync<TxResult$1, StakeError>;
224
+ }
225
+
226
+ interface StakeClient {
227
+ /** Reads the on-chain stake record for a user (stakedAmount, cooldownEnd, status). */
228
+ getUserStake(params: GetUserStakeParams): ResultAsync<UserStake, StakeError>;
229
+ /** Reads the per-currency stake boost config (tokens-per-USD, max boost). */
230
+ getStakeBoostConfig(params: GetStakeBoostConfigParams): ResultAsync<StakeBoostConfig, StakeError>;
231
+ /** Reads global stake boost configuration (token addr, cooldowns, totals). */
232
+ getStakeBoostGlobals(): ResultAsync<StakeBoostGlobals, StakeError>;
233
+ /** Reads the P2P token (ERC20) balance for a given address (raw bigint). */
234
+ getP2pTokenBalance(params: GetP2pTokenBalanceParams): ResultAsync<bigint, StakeError>;
235
+ readonly stake: StakeAction;
236
+ readonly topUp: TopUpAction;
237
+ readonly requestUnstake: RequestUnstakeAction;
238
+ readonly claimUnstake: ClaimUnstakeAction;
239
+ }
240
+
115
241
  type OrdersErrorCode = "VALIDATION_ERROR" | "INVALID_ORDER_ID" | "INVALID_GET_ORDERS_PARAMS" | "INVALID_FEE_CONFIG_PARAMS" | "ORDER_NOT_FOUND" | "CONTRACT_READ_FAILED" | "SUBGRAPH_REQUEST_FAILED" | "SUBGRAPH_VALIDATION_FAILED" | "MALFORMED_ORDER" | "CIRCLE_SELECTION_FAILED" | "ENCRYPTION_FAILED" | "RELAY_IDENTITY_CORRUPT" | "RELAY_IDENTITY_STORE_FAILED" | "TX_SUBMISSION_FAILED" | "RECEIPT_TIMEOUT" | "TX_REVERTED" | "EVENT_WATCH_FAILED";
116
242
  declare class OrdersError extends SdkError<OrdersErrorCode> {
117
243
  constructor(message: string, options: {
@@ -686,6 +812,7 @@ interface SdkConfig {
686
812
  readonly subgraphUrl: string;
687
813
  readonly diamondAddress: Address;
688
814
  readonly usdcAddress: Address;
815
+ readonly p2pTokenAddress: Address;
689
816
  readonly reputationManagerAddress?: Address;
690
817
  readonly fraudEngine?: FraudEngineSdkConfig;
691
818
  readonly orders?: OrdersSdkConfig;
@@ -695,6 +822,7 @@ interface Sdk {
695
822
  readonly profile: Profile;
696
823
  readonly prices: Prices;
697
824
  readonly orders: OrdersClient;
825
+ readonly stake: StakeClient;
698
826
  readonly zkkyc?: Zkkyc;
699
827
  readonly fraudEngine?: FraudEngine;
700
828
  }
@@ -724,6 +852,8 @@ declare function useProfile(): Profile;
724
852
  declare function usePrices(): Prices;
725
853
  /** Returns the Orders instance from the nearest SdkProvider. */
726
854
  declare function useOrders(): OrdersClient;
855
+ /** Returns the Stake instance from the nearest SdkProvider. */
856
+ declare function useStake(): StakeClient;
727
857
  /** Returns the Zkkyc instance from the nearest SdkProvider. */
728
858
  declare function useZkkyc(): Zkkyc;
729
859
  /** Returns the FraudEngine instance from the nearest SdkProvider. */
@@ -749,4 +879,4 @@ interface UseFingerprintResult {
749
879
  }
750
880
  declare function useFingerprint(enabled: boolean): UseFingerprintResult;
751
881
 
752
- export { type FraudEngineSdkConfig, type OrdersSdkConfig, type SdkConfig, SdkProvider, useFingerprint, useFraudEngine, useOrders, usePrices, useProfile, useSdk, useWatchOrders, useZkkyc };
882
+ export { type FraudEngineSdkConfig, type OrdersSdkConfig, type SdkConfig, SdkProvider, useFingerprint, useFraudEngine, useOrders, usePrices, useProfile, useSdk, useStake, useWatchOrders, useZkkyc };