@rhinestone/sdk 1.0.0-beta.38 → 1.0.0-beta.39
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/README.md
CHANGED
|
@@ -26,12 +26,37 @@ bun install viem @rhinestone/sdk
|
|
|
26
26
|
|
|
27
27
|
You'll need a Rhinestone API key, as well as an existing account with some testnet ETH on the source chain.
|
|
28
28
|
|
|
29
|
+
### SDK Initialization
|
|
30
|
+
|
|
31
|
+
To initialize the SDK with your configuration:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { RhinestoneSDK } from '@rhinestone/sdk'
|
|
35
|
+
|
|
36
|
+
const sdk = new RhinestoneSDK({
|
|
37
|
+
apiKey: 'your-rhinestone-api-key',
|
|
38
|
+
// Optional: Provider configuration
|
|
39
|
+
provider: {
|
|
40
|
+
type: 'alchemy',
|
|
41
|
+
apiKey: 'your-alchemy-api-key',
|
|
42
|
+
},
|
|
43
|
+
// Optional: Bundler configuration
|
|
44
|
+
bundler: {
|
|
45
|
+
// the bundler settings
|
|
46
|
+
},
|
|
47
|
+
// Optional: Paymaster configuration
|
|
48
|
+
paymaster: {
|
|
49
|
+
// the paymaster settings
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
```
|
|
53
|
+
|
|
29
54
|
### Creating a Wallet
|
|
30
55
|
|
|
31
56
|
Let's create a smart account with a single owner:
|
|
32
57
|
|
|
33
58
|
```ts
|
|
34
|
-
import {
|
|
59
|
+
import { RhinestoneSDK } from '@rhinestone/sdk'
|
|
35
60
|
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
|
|
36
61
|
import { baseSepolia, arbitrumSepolia, optimismSepolia } from 'viem/chains'
|
|
37
62
|
import {
|
|
@@ -63,12 +88,17 @@ const privateKey = generatePrivateKey()
|
|
|
63
88
|
console.info(`Owner private key: ${privateKey}`)
|
|
64
89
|
const account = privateKeyToAccount(privateKey)
|
|
65
90
|
|
|
66
|
-
|
|
91
|
+
// Initialize the SDK
|
|
92
|
+
const sdk = new RhinestoneSDK({
|
|
93
|
+
apiKey: rhinestoneApiKey,
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
// Create the Rhinestone account
|
|
97
|
+
const rhinestoneAccount = await sdk.createAccount({
|
|
67
98
|
owners: {
|
|
68
99
|
type: 'ecdsa',
|
|
69
100
|
accounts: [account],
|
|
70
|
-
}
|
|
71
|
-
rhinestoneApiKey,
|
|
101
|
+
},
|
|
72
102
|
})
|
|
73
103
|
const address = await rhinestoneAccount.getAddress()
|
|
74
104
|
console.info(`Smart account address: ${address}`)
|
|
@@ -182,13 +212,21 @@ const session: Session = {
|
|
|
182
212
|
During account initialization, provide the session you've just created. Make sure to also provide a bundler configuration.
|
|
183
213
|
|
|
184
214
|
```ts
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
215
|
+
// Initialize the SDK with bundler configuration
|
|
216
|
+
const sdk = new RhinestoneSDK({
|
|
217
|
+
apiKey: rhinestoneApiKey,
|
|
188
218
|
bundler: {
|
|
189
|
-
//
|
|
219
|
+
// bundler configuration
|
|
190
220
|
},
|
|
191
221
|
})
|
|
222
|
+
|
|
223
|
+
const rhinestoneAccount = await sdk.createAccount({
|
|
224
|
+
owners: {
|
|
225
|
+
type: 'ecdsa',
|
|
226
|
+
accounts: [account],
|
|
227
|
+
},
|
|
228
|
+
sessions: [session],
|
|
229
|
+
})
|
|
192
230
|
```
|
|
193
231
|
|
|
194
232
|
When making a transaction, specify the `signers` object to sign it with the session key:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../execution/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,KAAK,EAIV,KAAK,uBAAuB,EAC5B,KAAK,GAAG,EAIR,KAAK,YAAY,EAEjB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,SAAS,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AAM,EAAE,MAAM,GAAG,SAAS,EAC1B,eAAe,CAAC,EAAE,MAAM,0CAUzB;AAyBD,iBAAe,oBAAoB,CACjC,MAAM,EAAE,gBAAgB,EACxB,YAAY,EAAE,KAAK,EAAE,GAAG,SAAS,EACjC,WAAW,EAAE,KAAK,EAClB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,GAAG,EACd,cAAc,EAAE,uBAAuB,EACvC,MAAM,EAAE,OAAO,8BAmBhB;AAED,iBAAe,mBAAmB,CAChC,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,KAAK,yKA6Bb;AAmDD,iBAAS,UAAU,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,EAAE,CAMnE;AAgGD,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,0BAA0B,EAC1B,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,UAAU,EACV,0BAA0B,EAC1B,oBAAoB,EACpB,mBAAmB,EACnB,UAAU,EACV,gBAAgB,EAChB,iBAAiB,GAClB,CAAA;AACD,YAAY,EACV,WAAW,EACX,iBAAiB,EACjB,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,GACpB,CAAA"}
|
|
@@ -245,7 +245,7 @@ async function prepareTransactionAsUserOp(config, chain, callInputs, signers, ga
|
|
|
245
245
|
async function prepareTransactionAsIntent(config, sourceChains, targetChain, callInputs, gasLimit, tokenRequests, accountAddress, isSponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset, lockFunds) {
|
|
246
246
|
const calls = parseCalls(callInputs, targetChain.id);
|
|
247
247
|
const accountAccessList = createAccountAccessList(sourceChains, sourceAssets);
|
|
248
|
-
const { setupOps, delegations } = await getSetupOperationsAndDelegations(config,
|
|
248
|
+
const { setupOps, delegations } = await getSetupOperationsAndDelegations(config, accountAddress, eip7702InitSignature);
|
|
249
249
|
const getAccountType = (config) => {
|
|
250
250
|
if (config.account?.type === 'eoa') {
|
|
251
251
|
return 'EOA';
|
|
@@ -516,7 +516,7 @@ function createAccountAccessList(sourceChains, sourceAssets) {
|
|
|
516
516
|
}
|
|
517
517
|
return { chainTokens: sourceAssets };
|
|
518
518
|
}
|
|
519
|
-
async function getSetupOperationsAndDelegations(config,
|
|
519
|
+
async function getSetupOperationsAndDelegations(config, accountAddress, eip7702InitSignature) {
|
|
520
520
|
const initCode = (0, accounts_1.getInitCode)(config);
|
|
521
521
|
if (config.account?.type === 'eoa') {
|
|
522
522
|
return {
|
|
@@ -544,12 +544,6 @@ async function getSetupOperationsAndDelegations(config, chain, accountAddress, e
|
|
|
544
544
|
};
|
|
545
545
|
}
|
|
546
546
|
else if (initCode) {
|
|
547
|
-
const isAccountDeployed = await (0, accounts_1.isDeployed)(config, chain);
|
|
548
|
-
if (isAccountDeployed) {
|
|
549
|
-
return {
|
|
550
|
-
setupOps: [],
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
547
|
// Contract account with init code
|
|
554
548
|
return {
|
|
555
549
|
setupOps: [
|
|
@@ -15,6 +15,8 @@ export declare class Orchestrator {
|
|
|
15
15
|
getIntentRoute(input: IntentInput): Promise<IntentRoute>;
|
|
16
16
|
submitIntent(signedIntentOpUnformatted: SignedIntentOp, dryRun: boolean): Promise<IntentResult>;
|
|
17
17
|
getIntentOpStatus(intentId: bigint): Promise<IntentOpStatus>;
|
|
18
|
+
private getHeaders;
|
|
19
|
+
private fetch;
|
|
18
20
|
private parseError;
|
|
19
21
|
private parseErrorMessage;
|
|
20
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../orchestrator/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.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
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.Orchestrator = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
4
|
const viem_1 = require("viem");
|
|
9
5
|
const error_1 = require("./error");
|
|
10
6
|
const utils_1 = require("./utils");
|
|
@@ -16,41 +12,36 @@ class Orchestrator {
|
|
|
16
12
|
this.apiKey = apiKey;
|
|
17
13
|
}
|
|
18
14
|
async getPortfolio(userAddress, filter) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
chainIds: filter?.chainIds?.join(','),
|
|
23
|
-
tokens: filter?.tokens
|
|
24
|
-
? Object.entries(filter.tokens)
|
|
25
|
-
.map(([chainId, tokens]) => tokens.map((token) => `${chainId}:${token}`))
|
|
26
|
-
.reduce(viem_1.concat, [])
|
|
27
|
-
: undefined,
|
|
28
|
-
},
|
|
29
|
-
headers: {
|
|
30
|
-
'x-api-key': this.apiKey,
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
const portfolioResponse = response.data.portfolio;
|
|
34
|
-
const portfolio = portfolioResponse.map((tokenResponse) => ({
|
|
35
|
-
symbol: tokenResponse.tokenName,
|
|
36
|
-
decimals: tokenResponse.tokenDecimals,
|
|
37
|
-
balances: {
|
|
38
|
-
locked: BigInt(tokenResponse.balance.locked),
|
|
39
|
-
unlocked: BigInt(tokenResponse.balance.unlocked),
|
|
40
|
-
},
|
|
41
|
-
chains: tokenResponse.tokenChainBalance.map((chainBalance) => ({
|
|
42
|
-
chain: chainBalance.chainId,
|
|
43
|
-
address: chainBalance.tokenAddress,
|
|
44
|
-
locked: BigInt(chainBalance.balance.locked),
|
|
45
|
-
unlocked: BigInt(chainBalance.balance.unlocked),
|
|
46
|
-
})),
|
|
47
|
-
}));
|
|
48
|
-
return portfolio;
|
|
15
|
+
const params = new URLSearchParams();
|
|
16
|
+
if (filter?.chainIds) {
|
|
17
|
+
params.set('chainIds', filter.chainIds.join(','));
|
|
49
18
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
19
|
+
if (filter?.tokens) {
|
|
20
|
+
params.set('tokens', Object.entries(filter.tokens)
|
|
21
|
+
.flatMap(([chainId, tokens]) => tokens.map((token) => `${chainId}:${token}`))
|
|
22
|
+
.join(','));
|
|
53
23
|
}
|
|
24
|
+
const url = new URL(`${this.serverUrl}/accounts/${userAddress}/portfolio`);
|
|
25
|
+
url.search = params.toString();
|
|
26
|
+
const json = await this.fetch(url.toString(), {
|
|
27
|
+
headers: this.getHeaders(),
|
|
28
|
+
});
|
|
29
|
+
const portfolioResponse = json.portfolio;
|
|
30
|
+
const portfolio = portfolioResponse.map((tokenResponse) => ({
|
|
31
|
+
symbol: tokenResponse.tokenName,
|
|
32
|
+
decimals: tokenResponse.tokenDecimals,
|
|
33
|
+
balances: {
|
|
34
|
+
locked: BigInt(tokenResponse.balance.locked),
|
|
35
|
+
unlocked: BigInt(tokenResponse.balance.unlocked),
|
|
36
|
+
},
|
|
37
|
+
chains: tokenResponse.tokenChainBalance.map((chainBalance) => ({
|
|
38
|
+
chain: chainBalance.chainId,
|
|
39
|
+
address: chainBalance.tokenAddress,
|
|
40
|
+
locked: BigInt(chainBalance.balance.locked),
|
|
41
|
+
unlocked: BigInt(chainBalance.balance.unlocked),
|
|
42
|
+
})),
|
|
43
|
+
}));
|
|
44
|
+
return portfolio;
|
|
54
45
|
}
|
|
55
46
|
async getMaxTokenAmount(userAddress, destinationChainId, destinationTokenAddress, destinationGasUnits, sponsored) {
|
|
56
47
|
const intentCost = await this.getIntentCost({
|
|
@@ -100,74 +91,60 @@ class Orchestrator {
|
|
|
100
91
|
: tokenReceived.destinationAmount;
|
|
101
92
|
}
|
|
102
93
|
async getIntentCost(input) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
'x-api-key': this.apiKey,
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
return response.data;
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
this.parseError(error);
|
|
115
|
-
throw new error_1.OrchestratorError({ message: 'Failed to get intent cost' });
|
|
116
|
-
}
|
|
94
|
+
return await this.fetch(`${this.serverUrl}/intents/cost`, {
|
|
95
|
+
method: 'POST',
|
|
96
|
+
headers: this.getHeaders(),
|
|
97
|
+
body: JSON.stringify((0, utils_1.convertBigIntFields)(input)),
|
|
98
|
+
});
|
|
117
99
|
}
|
|
118
100
|
async getIntentRoute(input) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
'x-api-key': this.apiKey,
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
return response.data;
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
this.parseError(error);
|
|
131
|
-
throw new error_1.OrchestratorError({ message: 'Failed to get intent route' });
|
|
132
|
-
}
|
|
101
|
+
return await this.fetch(`${this.serverUrl}/intents/route`, {
|
|
102
|
+
method: 'POST',
|
|
103
|
+
headers: this.getHeaders(),
|
|
104
|
+
body: JSON.stringify((0, utils_1.convertBigIntFields)(input)),
|
|
105
|
+
});
|
|
133
106
|
}
|
|
134
107
|
async submitIntent(signedIntentOpUnformatted, dryRun) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
const response = await axios_1.default.post(`${this.serverUrl}/intent-operations`, {
|
|
143
|
-
signedIntentOp,
|
|
144
|
-
}, {
|
|
145
|
-
headers: {
|
|
146
|
-
'x-api-key': this.apiKey,
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
return response.data;
|
|
150
|
-
}
|
|
151
|
-
catch (error) {
|
|
152
|
-
this.parseError(error);
|
|
153
|
-
throw new error_1.OrchestratorError({ message: 'Failed to submit intent' });
|
|
108
|
+
const signedIntentOp = (0, utils_1.convertBigIntFields)(signedIntentOpUnformatted);
|
|
109
|
+
if (dryRun) {
|
|
110
|
+
signedIntentOp.options = {
|
|
111
|
+
dryRun: true,
|
|
112
|
+
};
|
|
154
113
|
}
|
|
114
|
+
return await this.fetch(`${this.serverUrl}/intent-operations`, {
|
|
115
|
+
method: 'POST',
|
|
116
|
+
headers: this.getHeaders(),
|
|
117
|
+
body: JSON.stringify({
|
|
118
|
+
signedIntentOp,
|
|
119
|
+
}),
|
|
120
|
+
});
|
|
155
121
|
}
|
|
156
122
|
async getIntentOpStatus(intentId) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
123
|
+
return await this.fetch(`${this.serverUrl}/intent-operation/${intentId.toString()}/status`, {
|
|
124
|
+
headers: this.getHeaders(),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
getHeaders() {
|
|
128
|
+
const headers = {
|
|
129
|
+
'Content-Type': 'application/json',
|
|
130
|
+
};
|
|
131
|
+
if (this.apiKey) {
|
|
132
|
+
headers['x-api-key'] = this.apiKey;
|
|
164
133
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
134
|
+
return headers;
|
|
135
|
+
}
|
|
136
|
+
async fetch(url, options) {
|
|
137
|
+
const response = await fetch(url, options);
|
|
138
|
+
if (!response.ok) {
|
|
139
|
+
const errorData = await response.json().catch(() => ({}));
|
|
140
|
+
this.parseError({
|
|
141
|
+
response: {
|
|
142
|
+
status: response.status,
|
|
143
|
+
data: errorData,
|
|
144
|
+
},
|
|
169
145
|
});
|
|
170
146
|
}
|
|
147
|
+
return response.json();
|
|
171
148
|
}
|
|
172
149
|
parseError(error) {
|
|
173
150
|
if (error.response) {
|
|
@@ -200,41 +177,30 @@ class Orchestrator {
|
|
|
200
177
|
}
|
|
201
178
|
}
|
|
202
179
|
let context = {};
|
|
203
|
-
if (error.response.data) {
|
|
204
|
-
|
|
205
|
-
if (message) {
|
|
206
|
-
const mainErrorParams = {
|
|
207
|
-
context: { traceId },
|
|
208
|
-
errorType,
|
|
209
|
-
traceId,
|
|
210
|
-
};
|
|
211
|
-
this.parseErrorMessage(message, mainErrorParams);
|
|
212
|
-
}
|
|
213
|
-
for (const err of errors) {
|
|
214
|
-
let errorMessage = `Rhinestone Error: ${err.message}`;
|
|
215
|
-
if (errorType) {
|
|
216
|
-
errorMessage += ` (${errorType})`;
|
|
217
|
-
}
|
|
218
|
-
if (traceId) {
|
|
219
|
-
errorMessage += ` [Trace ID: ${traceId}]`;
|
|
220
|
-
context.traceId = traceId;
|
|
221
|
-
}
|
|
222
|
-
console.error(errorMessage);
|
|
223
|
-
if (err.context) {
|
|
224
|
-
console.error(`Context: ${JSON.stringify(err.context, undefined, 4)}`);
|
|
225
|
-
}
|
|
226
|
-
context = { ...context, ...err.context };
|
|
227
|
-
const message = err.message;
|
|
228
|
-
const finalErrorParams = {
|
|
229
|
-
context: { ...context, traceId },
|
|
230
|
-
errorType,
|
|
231
|
-
traceId,
|
|
232
|
-
};
|
|
233
|
-
this.parseErrorMessage(message, finalErrorParams);
|
|
234
|
-
}
|
|
180
|
+
if (!error.response.data) {
|
|
181
|
+
return;
|
|
235
182
|
}
|
|
236
|
-
|
|
237
|
-
|
|
183
|
+
const { errors, traceId, message } = error.response.data;
|
|
184
|
+
if (message) {
|
|
185
|
+
const mainErrorParams = {
|
|
186
|
+
context: { traceId },
|
|
187
|
+
errorType,
|
|
188
|
+
traceId,
|
|
189
|
+
};
|
|
190
|
+
this.parseErrorMessage(message, mainErrorParams);
|
|
191
|
+
}
|
|
192
|
+
for (const err of errors) {
|
|
193
|
+
if (traceId) {
|
|
194
|
+
context.traceId = traceId;
|
|
195
|
+
}
|
|
196
|
+
context = { ...context, ...err.context };
|
|
197
|
+
const message = err.message;
|
|
198
|
+
const finalErrorParams = {
|
|
199
|
+
context: { ...context, traceId },
|
|
200
|
+
errorType,
|
|
201
|
+
traceId,
|
|
202
|
+
};
|
|
203
|
+
this.parseErrorMessage(message, finalErrorParams);
|
|
238
204
|
}
|
|
239
205
|
}
|
|
240
206
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhinestone/sdk",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.39",
|
|
4
4
|
"description": "End-to-end chain abstraction and modularity toolkit",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Rhinestone",
|
|
@@ -107,7 +107,6 @@
|
|
|
107
107
|
},
|
|
108
108
|
"dependencies": {
|
|
109
109
|
"@rhinestone/shared-configs": "^1.4.4",
|
|
110
|
-
"axios": "^1.7.0",
|
|
111
110
|
"solady": "^0.1.21"
|
|
112
111
|
},
|
|
113
112
|
"peerDependencies": {
|