@renegade-fi/renegade-sdk 0.1.6 → 0.1.7

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.
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Basic example of using the Renegade External Match Client
3
+ *
4
+ * This example demonstrates how to create a client, request a quote, assemble a match, and submit the transaction on-chain.
5
+ */
6
+
7
+ import { ExternalMatchClient, OrderSide } from "../index";
8
+ import type { ExternalOrder } from "../index";
9
+
10
+ // Viem imports for on-chain transactions
11
+ import { http, createWalletClient } from "viem";
12
+ import { privateKeyToAccount } from "viem/accounts";
13
+ import { baseSepolia } from "viem/chains";
14
+
15
+ // Get API credentials from environment variables
16
+ const API_KEY = process.env.EXTERNAL_MATCH_KEY || "";
17
+ const API_SECRET = process.env.EXTERNAL_MATCH_SECRET || "";
18
+ const PRIVATE_KEY = process.env.PKEY || "";
19
+ const RPC_URL = process.env.RPC_URL || "https://sepolia.base.org";
20
+
21
+ // Validate API credentials
22
+ if (!API_KEY || !API_SECRET) {
23
+ console.error("Error: Missing API credentials");
24
+ console.error("Please set EXTERNAL_MATCH_KEY and EXTERNAL_MATCH_SECRET environment variables");
25
+ process.exit(1);
26
+ }
27
+
28
+ // Validate wallet private key
29
+ if (!PRIVATE_KEY) {
30
+ console.error("Error: Missing private key");
31
+ console.error("Please set PKEY environment variable");
32
+ process.exit(1);
33
+ }
34
+
35
+ // Set up wallet client for blockchain transactions
36
+ const privateKey = PRIVATE_KEY.startsWith("0x") ? PRIVATE_KEY : `0x${PRIVATE_KEY}`;
37
+ const walletClient = createWalletClient({
38
+ account: privateKeyToAccount(privateKey as `0x${string}`),
39
+ chain: baseSepolia,
40
+ transport: http(RPC_URL),
41
+ });
42
+
43
+ // Create the external match client
44
+ console.log("API KEY", API_KEY);
45
+ const client = ExternalMatchClient.newBaseSepoliaClient(API_KEY, API_SECRET);
46
+
47
+ // Example order for USDC/WETH pair
48
+ const order: ExternalOrder = {
49
+ quote_mint: "0xD9961Bb4Cb27192f8dAd20a662be081f546b0E74", // USDC on testnet
50
+ base_mint: "0xb51a558c8E55DE1EE5391BDFe2aFA49968FC3B25", // cbBTC on testnet
51
+ side: OrderSide.BUY,
52
+ quote_amount: BigInt(20_000_000), // 20 USDC
53
+ };
54
+
55
+ /**
56
+ * Submit a transaction to the chain
57
+ * @param settlementTx The settlement transaction
58
+ * @returns The transaction hash
59
+ */
60
+ async function submitTransaction(settlementTx: any): Promise<`0x${string}`> {
61
+ console.log("Submitting transaction...");
62
+
63
+ const tx = await walletClient.sendTransaction({
64
+ to: settlementTx.to as `0x${string}`,
65
+ data: settlementTx.data as `0x${string}`,
66
+ value: settlementTx.value ? BigInt(settlementTx.value) : BigInt(0),
67
+ });
68
+
69
+ return tx;
70
+ }
71
+
72
+ // Full example with on-chain submission
73
+ async function fullExample() {
74
+ try {
75
+ // Step 1: Request a quote
76
+ console.log("Requesting quote...");
77
+ const quote = await client.requestQuote(order);
78
+
79
+ if (!quote) {
80
+ console.log("No quote available");
81
+ return;
82
+ }
83
+
84
+ console.log("Quote received!");
85
+
86
+ // Step 2: Assemble the quote into a match bundle
87
+ console.log("Assembling match...");
88
+ const bundle = await client.assembleQuote(quote);
89
+
90
+ if (!bundle) {
91
+ console.log("No match available");
92
+ return;
93
+ }
94
+
95
+ console.log("Match assembled!");
96
+
97
+ // Step 3: Submit the transaction on-chain
98
+ const txHash = await submitTransaction(bundle.match_bundle.settlement_tx);
99
+ console.log(
100
+ "Transaction submitted:",
101
+ `${walletClient.chain.blockExplorers?.default.url}/tx/${txHash}`,
102
+ );
103
+ } catch (error) {
104
+ console.error("Error:", error);
105
+ }
106
+ }
107
+
108
+ // Run the examples
109
+ async function main() {
110
+ console.log("Running full example with on-chain submission...");
111
+ await fullExample();
112
+ }
113
+
114
+ // Only run if this file is being executed directly
115
+ if (require.main === module) {
116
+ main().catch(console.error);
117
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@renegade-fi/renegade-sdk",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "A TypeScript client for interacting with the Renegade Darkpool API",
5
5
  "module": "index.ts",
6
6
  "type": "module",
package/src/client.ts CHANGED
@@ -22,6 +22,8 @@ import { VERSION } from "./version";
22
22
  // Constants for API URLs
23
23
  const ARBITRUM_SEPOLIA_BASE_URL = "https://arbitrum-sepolia.auth-server.renegade.fi";
24
24
  const ARBITRUM_ONE_BASE_URL = "https://arbitrum-one.auth-server.renegade.fi";
25
+ const BASE_SEPOLIA_BASE_URL = "https://base-sepolia.auth-server.renegade.fi";
26
+ const BASE_MAINNET_BASE_URL = "https://base-mainnet.auth-server.renegade.fi";
25
27
 
26
28
  // Header constants
27
29
  const RENEGADE_API_KEY_HEADER = "x-renegade-api-key";
@@ -290,6 +292,17 @@ export class ExternalMatchClient {
290
292
  return new ExternalMatchClient(apiKey, apiSecret, ARBITRUM_SEPOLIA_BASE_URL);
291
293
  }
292
294
 
295
+ /**
296
+ * Create a new client configured for the Base Sepolia testnet.
297
+ *
298
+ * @param apiKey The API key for authentication
299
+ * @param apiSecret The API secret for request signing
300
+ * @returns A new ExternalMatchClient configured for Sepolia
301
+ */
302
+ static newBaseSepoliaClient(apiKey: string, apiSecret: string): ExternalMatchClient {
303
+ return new ExternalMatchClient(apiKey, apiSecret, BASE_SEPOLIA_BASE_URL);
304
+ }
305
+
293
306
  /**
294
307
  * Create a new client configured for the Arbitrum One mainnet.
295
308
  *
@@ -310,6 +323,17 @@ export class ExternalMatchClient {
310
323
  return new ExternalMatchClient(apiKey, apiSecret, ARBITRUM_ONE_BASE_URL);
311
324
  }
312
325
 
326
+ /**
327
+ * Create a new client configured for the Base mainnet.
328
+ *
329
+ * @param apiKey The API key for authentication
330
+ * @param apiSecret The API secret for request signing
331
+ * @returns A new ExternalMatchClient configured for mainnet
332
+ */
333
+ static newBaseMainnetClient(apiKey: string, apiSecret: string): ExternalMatchClient {
334
+ return new ExternalMatchClient(apiKey, apiSecret, BASE_MAINNET_BASE_URL);
335
+ }
336
+
313
337
  /**
314
338
  * Request a quote for the given order.
315
339
  *
package/src/version.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * SDK version information
3
3
  * This file is automatically updated during the build process
4
- * Last updated: 2025-05-21T22:43:53Z
4
+ * Last updated: 2025-05-30T00:51:32Z
5
5
  */
6
6
 
7
- export const VERSION = '0.1.6';
7
+ export const VERSION = '0.1.7';