@renegade-fi/renegade-sdk 0.1.0 → 0.1.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.
@@ -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 {
8
+ AssembleExternalMatchOptions,
9
+ ExternalMatchClient,
10
+ OrderSide,
11
+ } from '../index';
12
+ import type { ExternalOrder } from '../index';
13
+ import { stringifyBigJSON } from '../src/http';
14
+
15
+ // Viem imports for on-chain transactions
16
+ import { http, createWalletClient } from 'viem';
17
+ import { privateKeyToAccount } from 'viem/accounts';
18
+ import { arbitrumSepolia } from 'viem/chains';
19
+
20
+ // Get API credentials from environment variables
21
+ const API_KEY = process.env.EXTERNAL_MATCH_KEY || '';
22
+ const API_SECRET = process.env.EXTERNAL_MATCH_SECRET || '';
23
+ const PRIVATE_KEY = process.env.PKEY || '';
24
+ const RPC_URL = process.env.RPC_URL || 'https://sepolia-rollup.arbitrum.io/rpc';
25
+
26
+ // Validate API credentials
27
+ if (!API_KEY || !API_SECRET) {
28
+ console.error('Error: Missing API credentials');
29
+ console.error('Please set EXTERNAL_MATCH_KEY and EXTERNAL_MATCH_SECRET environment variables');
30
+ process.exit(1);
31
+ }
32
+
33
+ // Validate wallet private key
34
+ if (!PRIVATE_KEY) {
35
+ console.error('Error: Missing private key');
36
+ console.error('Please set PRIVATE_KEY environment variable');
37
+ process.exit(1);
38
+ }
39
+
40
+ // Set up wallet client for blockchain transactions
41
+ const privateKey = PRIVATE_KEY.startsWith('0x') ? PRIVATE_KEY : `0x${PRIVATE_KEY}`;
42
+ const walletClient = createWalletClient({
43
+ account: privateKeyToAccount(privateKey as `0x${string}`),
44
+ chain: arbitrumSepolia,
45
+ transport: http(RPC_URL),
46
+ });
47
+
48
+ // Create the external match client
49
+ console.log('API KEY', API_KEY);
50
+ const client = ExternalMatchClient.newSepoliaClient(API_KEY, API_SECRET);
51
+
52
+ // Example order for USDC/WETH pair
53
+ const order: ExternalOrder = {
54
+ quote_mint: '0xdf8d259c04020562717557f2b5a3cf28e92707d1', // USDC
55
+ base_mint: '0xc3414a7ef14aaaa9c4522dfc00a4e66e74e9c25a', // WETH
56
+ side: OrderSide.BUY,
57
+ quote_amount: BigInt(20_000_000), // 20 USDC
58
+ };
59
+
60
+ /**
61
+ * Submit a transaction to the chain
62
+ * @param settlementTx The settlement transaction
63
+ * @returns The transaction hash
64
+ */
65
+ async function submitTransaction(settlementTx: any): Promise<`0x${string}`> {
66
+ console.log('Submitting transaction...');
67
+
68
+ const tx = await walletClient.sendTransaction({
69
+ to: settlementTx.to as `0x${string}`,
70
+ data: settlementTx.data as `0x${string}`,
71
+ value: settlementTx.value ? BigInt(settlementTx.value) : BigInt(0),
72
+ });
73
+
74
+ return tx;
75
+ }
76
+
77
+ // Run the examples
78
+ async function main() {
79
+ try {
80
+ // Step 1: Request a quote
81
+ console.log('Requesting quote...');
82
+ const quote = await client.requestQuote(order);
83
+
84
+ if (!quote) {
85
+ console.log('No quote available');
86
+ return;
87
+ }
88
+
89
+ console.log('Quote received!');
90
+
91
+ // Step 2: Assemble the quote into a match bundle
92
+ console.log('Assembling match...');
93
+ const options = AssembleExternalMatchOptions.new().withAllowShared(true);
94
+ const bundle = await client.assembleQuoteWithOptions(quote, options);
95
+
96
+ if (!bundle) {
97
+ console.log('No match available');
98
+ return;
99
+ }
100
+
101
+ console.log('Match assembled!');
102
+
103
+ // Step 3: Submit the transaction on-chain
104
+ const txHash = await submitTransaction(bundle.match_bundle.settlement_tx);
105
+ console.log(
106
+ 'Transaction submitted:',
107
+ `${walletClient.chain.blockExplorers?.default.url}/tx/${txHash}`
108
+ );
109
+ } catch (error) {
110
+ console.error('Error:', error);
111
+ }
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.0",
3
+ "version": "0.1.2",
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
@@ -106,6 +106,7 @@ export class RequestQuoteOptions {
106
106
  */
107
107
  export class AssembleExternalMatchOptions {
108
108
  doGasEstimation: boolean = false;
109
+ allowShared: boolean = false;
109
110
  receiverAddress?: string;
110
111
  updatedOrder?: ExternalOrder;
111
112
  requestGasSponsorship: boolean = false;
@@ -126,6 +127,14 @@ export class AssembleExternalMatchOptions {
126
127
  return this;
127
128
  }
128
129
 
130
+ /**
131
+ * Set whether to allow shared gas sponsorship.
132
+ */
133
+ withAllowShared(allowShared: boolean): AssembleExternalMatchOptions {
134
+ this.allowShared = allowShared;
135
+ return this;
136
+ }
137
+
129
138
  /**
130
139
  * Set the receiver address.
131
140
  */
@@ -326,10 +335,10 @@ export class ExternalMatchClient {
326
335
 
327
336
  const request: AssembleExternalMatchRequest = {
328
337
  do_gas_estimation: options.doGasEstimation,
338
+ allow_shared: options.allowShared,
329
339
  receiver_address: options.receiverAddress,
330
340
  signed_quote: signedQuote,
331
341
  updated_order: options.updatedOrder,
332
- gas_sponsorship_info: quote.gas_sponsorship_info,
333
342
  };
334
343
 
335
344
  const path = options.buildRequestPath();
package/src/types.ts CHANGED
@@ -99,10 +99,10 @@ export interface ExternalQuoteResponse {
99
99
 
100
100
  export interface AssembleExternalMatchRequest {
101
101
  do_gas_estimation?: boolean;
102
+ allow_shared?: boolean;
102
103
  receiver_address?: string;
103
104
  signed_quote: ApiSignedExternalQuote;
104
105
  updated_order?: ExternalOrder;
105
- gas_sponsorship_info?: SignedGasSponsorshipInfo;
106
106
  }
107
107
 
108
108
  export interface ExternalMatchResponse {
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-03-27T00:13:04Z
4
+ * Last updated: 2025-04-17T02:29:21Z
5
5
  */
6
6
 
7
- export const VERSION = '0.1.0';
7
+ export const VERSION = '0.1.2';