@smoothsend/sdk 2.2.11 → 2.3.1
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/avax/SmoothSendAvaxClient.d.ts +67 -0
- package/dist/avax/SmoothSendAvaxClient.d.ts.map +1 -0
- package/dist/avax/SmoothSendAvaxSubmitter.d.ts +24 -1
- package/dist/avax/SmoothSendAvaxSubmitter.d.ts.map +1 -1
- package/dist/avax/index.cjs +308 -0
- package/dist/avax/index.cjs.map +1 -1
- package/dist/avax/index.d.ts +126 -3
- package/dist/avax/index.d.ts.map +1 -1
- package/dist/avax/index.js +307 -1
- package/dist/avax/index.js.map +1 -1
- package/dist/avax/types.d.ts +16 -0
- package/dist/avax/types.d.ts.map +1 -1
- package/dist/avax/useSmoothSendAvax.d.ts +21 -1
- package/dist/avax/useSmoothSendAvax.d.ts.map +1 -1
- package/dist/avax-entry.d.ts +1 -1
- package/dist/avax-entry.d.ts.map +1 -1
- package/dist/index.cjs +308 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +307 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2797,6 +2797,38 @@ class SmoothSendAvaxSubmitter {
|
|
|
2797
2797
|
}
|
|
2798
2798
|
return data;
|
|
2799
2799
|
}
|
|
2800
|
+
/**
|
|
2801
|
+
* Preflight fee estimate for `user-pays-erc20` mode.
|
|
2802
|
+
*
|
|
2803
|
+
* This performs:
|
|
2804
|
+
* 1) `eth_estimateUserOperationGas`
|
|
2805
|
+
* 2) `paymaster/sign` in `user-pays-erc20` mode
|
|
2806
|
+
* and returns `feePreview` when available.
|
|
2807
|
+
*/
|
|
2808
|
+
async estimateUserPaysFee(opts) {
|
|
2809
|
+
const entryPoint = opts.entryPoint ?? (await this.getSupportedEntryPoints())[0];
|
|
2810
|
+
if (!entryPoint) {
|
|
2811
|
+
throw new Error('[SmoothSendAvaxSubmitter] no EntryPoint from bundler');
|
|
2812
|
+
}
|
|
2813
|
+
let userOp = {
|
|
2814
|
+
...opts.userOp,
|
|
2815
|
+
signature: opts.userOp.signature ?? '0x',
|
|
2816
|
+
};
|
|
2817
|
+
const gas = await this.estimateUserOperationGas(userOp, entryPoint);
|
|
2818
|
+
userOp = SmoothSendAvaxSubmitter.applyGasEstimate(userOp, gas);
|
|
2819
|
+
const signedPm = await this.paymasterSign({
|
|
2820
|
+
mode: 'user-pays-erc20',
|
|
2821
|
+
userOp,
|
|
2822
|
+
...opts.paymaster,
|
|
2823
|
+
});
|
|
2824
|
+
return {
|
|
2825
|
+
entryPoint,
|
|
2826
|
+
userOp,
|
|
2827
|
+
gas,
|
|
2828
|
+
exchangeRate: signedPm.exchangeRate,
|
|
2829
|
+
feePreview: signedPm.feePreview,
|
|
2830
|
+
};
|
|
2831
|
+
}
|
|
2800
2832
|
async getBundlerHealth() {
|
|
2801
2833
|
const res = await this.http.get('/api/v1/bundler/health');
|
|
2802
2834
|
if (!res.success)
|
|
@@ -3037,6 +3069,178 @@ function encodeCreateAccountFactoryData(owner, salt) {
|
|
|
3037
3069
|
});
|
|
3038
3070
|
}
|
|
3039
3071
|
|
|
3072
|
+
class SmoothSendAvaxClient {
|
|
3073
|
+
constructor(config) {
|
|
3074
|
+
this.config = config;
|
|
3075
|
+
this.submitter = new SmoothSendAvaxSubmitter({
|
|
3076
|
+
apiKey: config.apiKey,
|
|
3077
|
+
network: config.network,
|
|
3078
|
+
gatewayUrl: config.gatewayUrl,
|
|
3079
|
+
timeout: config.timeout,
|
|
3080
|
+
chain: config.chain,
|
|
3081
|
+
corsOrigin: config.corsOrigin
|
|
3082
|
+
});
|
|
3083
|
+
}
|
|
3084
|
+
async submitCall(args) {
|
|
3085
|
+
return this.submitCalls({
|
|
3086
|
+
calls: [args.call],
|
|
3087
|
+
mode: args.mode,
|
|
3088
|
+
paymaster: args.paymaster,
|
|
3089
|
+
smartAccountAddress: args.smartAccountAddress,
|
|
3090
|
+
accountFactory: args.accountFactory,
|
|
3091
|
+
accountSalt: args.accountSalt,
|
|
3092
|
+
waitForReceipt: args.waitForReceipt
|
|
3093
|
+
});
|
|
3094
|
+
}
|
|
3095
|
+
async submitCalls(args) {
|
|
3096
|
+
if (args.calls.length === 0) {
|
|
3097
|
+
throw new Error('[SmoothSend AVAX] No calls provided');
|
|
3098
|
+
}
|
|
3099
|
+
const built = await this.buildDraft(args.calls, {
|
|
3100
|
+
smartAccountAddress: args.smartAccountAddress,
|
|
3101
|
+
accountFactory: args.accountFactory,
|
|
3102
|
+
accountSalt: args.accountSalt
|
|
3103
|
+
});
|
|
3104
|
+
const result = await this.submitter.submitSponsoredUserOperation({
|
|
3105
|
+
userOp: built.userOp,
|
|
3106
|
+
mode: args.mode ?? 'developer-sponsored',
|
|
3107
|
+
paymaster: args.paymaster,
|
|
3108
|
+
waitForReceipt: args.waitForReceipt,
|
|
3109
|
+
signUserOp: async (op) => {
|
|
3110
|
+
const hash = hashUserOperationAvax({
|
|
3111
|
+
chainId: built.chainId,
|
|
3112
|
+
entryPointAddress: built.entryPoint,
|
|
3113
|
+
userOperation: op
|
|
3114
|
+
});
|
|
3115
|
+
return this.signUserOpHash(hash);
|
|
3116
|
+
}
|
|
3117
|
+
});
|
|
3118
|
+
return {
|
|
3119
|
+
userOpHash: result.userOpHash,
|
|
3120
|
+
transactionHash: result.receipt?.receipt?.transactionHash,
|
|
3121
|
+
receipt: result.receipt
|
|
3122
|
+
};
|
|
3123
|
+
}
|
|
3124
|
+
async estimateUserPaysFee(args) {
|
|
3125
|
+
if (args.calls.length === 0) {
|
|
3126
|
+
throw new Error('[SmoothSend AVAX] No calls provided');
|
|
3127
|
+
}
|
|
3128
|
+
const built = await this.buildDraft(args.calls, {
|
|
3129
|
+
smartAccountAddress: args.smartAccountAddress,
|
|
3130
|
+
accountFactory: args.accountFactory,
|
|
3131
|
+
accountSalt: args.accountSalt
|
|
3132
|
+
});
|
|
3133
|
+
const estimate = await this.submitter.estimateUserPaysFee({
|
|
3134
|
+
userOp: built.userOp,
|
|
3135
|
+
entryPoint: built.entryPoint,
|
|
3136
|
+
paymaster: args.paymaster
|
|
3137
|
+
});
|
|
3138
|
+
return {
|
|
3139
|
+
feePreview: estimate.feePreview,
|
|
3140
|
+
exchangeRate: estimate.exchangeRate,
|
|
3141
|
+
entryPoint: estimate.entryPoint
|
|
3142
|
+
};
|
|
3143
|
+
}
|
|
3144
|
+
async buildDraft(calls, overrides) {
|
|
3145
|
+
const { publicClient, walletClient } = this.config;
|
|
3146
|
+
const account = walletClient.account;
|
|
3147
|
+
if (!account) {
|
|
3148
|
+
throw new Error('[SmoothSend AVAX] walletClient.account missing');
|
|
3149
|
+
}
|
|
3150
|
+
const ownerAddress = account.address;
|
|
3151
|
+
const defaults = await this.submitter.getPublicAaDefaults().catch(() => null);
|
|
3152
|
+
const accountFactory = overrides?.accountFactory ??
|
|
3153
|
+
this.config.accountFactory ??
|
|
3154
|
+
((this.config.network ?? 'testnet') === 'mainnet'
|
|
3155
|
+
? defaults?.simpleAccountFactoryMainnet
|
|
3156
|
+
: defaults?.simpleAccountFactoryFuji) ??
|
|
3157
|
+
undefined;
|
|
3158
|
+
const accountSalt = overrides?.accountSalt ?? this.config.accountSalt ?? 0n;
|
|
3159
|
+
const smartAccountAddress = overrides?.smartAccountAddress ?? this.config.smartAccountAddress;
|
|
3160
|
+
const chainId = Number(publicClient.chain?.id ?? (await publicClient.getChainId()));
|
|
3161
|
+
const entryPoint = (await this.submitter.getSupportedEntryPoints())[0];
|
|
3162
|
+
let sender;
|
|
3163
|
+
if (accountFactory) {
|
|
3164
|
+
const predicted = await predictSimpleAccountAddress({
|
|
3165
|
+
publicClient,
|
|
3166
|
+
factory: accountFactory,
|
|
3167
|
+
owner: ownerAddress,
|
|
3168
|
+
salt: accountSalt
|
|
3169
|
+
});
|
|
3170
|
+
if (smartAccountAddress &&
|
|
3171
|
+
predicted.toLowerCase() !== smartAccountAddress.toLowerCase()) {
|
|
3172
|
+
throw new Error(`[SmoothSend AVAX] smartAccountAddress ${smartAccountAddress} does not match factory prediction ${predicted}`);
|
|
3173
|
+
}
|
|
3174
|
+
sender = predicted;
|
|
3175
|
+
}
|
|
3176
|
+
else if (smartAccountAddress) {
|
|
3177
|
+
sender = smartAccountAddress;
|
|
3178
|
+
}
|
|
3179
|
+
else {
|
|
3180
|
+
throw new Error('[SmoothSend AVAX] Provide smartAccountAddress or accountFactory (or use gateway public defaults).');
|
|
3181
|
+
}
|
|
3182
|
+
const code = await publicClient.getBytecode({ address: sender });
|
|
3183
|
+
const deployed = typeof code === 'string' && code !== '0x' && code.length > 2;
|
|
3184
|
+
let nonce;
|
|
3185
|
+
let factory;
|
|
3186
|
+
let factoryData;
|
|
3187
|
+
if (!deployed) {
|
|
3188
|
+
if (!accountFactory) {
|
|
3189
|
+
throw new Error('[SmoothSend AVAX] Sender is not deployed and no accountFactory available');
|
|
3190
|
+
}
|
|
3191
|
+
nonce = 0n;
|
|
3192
|
+
factory = accountFactory;
|
|
3193
|
+
factoryData = encodeCreateAccountFactoryData(ownerAddress, accountSalt);
|
|
3194
|
+
}
|
|
3195
|
+
else {
|
|
3196
|
+
nonce = await readAvaxSenderNonce({
|
|
3197
|
+
publicClient,
|
|
3198
|
+
entryPointAddress: entryPoint,
|
|
3199
|
+
sender
|
|
3200
|
+
});
|
|
3201
|
+
}
|
|
3202
|
+
let maxFeePerGas = 50n * 10n ** 9n;
|
|
3203
|
+
let maxPriorityFeePerGas = 2n * 10n ** 9n;
|
|
3204
|
+
try {
|
|
3205
|
+
const est = await publicClient.estimateFeesPerGas();
|
|
3206
|
+
if (est.maxFeePerGas)
|
|
3207
|
+
maxFeePerGas = est.maxFeePerGas;
|
|
3208
|
+
if (est.maxPriorityFeePerGas)
|
|
3209
|
+
maxPriorityFeePerGas = est.maxPriorityFeePerGas;
|
|
3210
|
+
}
|
|
3211
|
+
catch {
|
|
3212
|
+
// ignore and use fallbacks
|
|
3213
|
+
}
|
|
3214
|
+
const callData = calls.length === 1
|
|
3215
|
+
? encodeAvaxExecuteCalldata(calls[0].to, calls[0].value ?? 0n, calls[0].data ?? '0x')
|
|
3216
|
+
: encodeAvaxExecuteBatchCalldata(calls.map((c) => c.to), calls.map((c) => c.value ?? 0n), calls.map((c) => c.data ?? '0x'));
|
|
3217
|
+
return {
|
|
3218
|
+
userOp: {
|
|
3219
|
+
sender,
|
|
3220
|
+
nonce: toHex(nonce),
|
|
3221
|
+
callData,
|
|
3222
|
+
maxFeePerGas: toHex(maxFeePerGas),
|
|
3223
|
+
maxPriorityFeePerGas: toHex(maxPriorityFeePerGas),
|
|
3224
|
+
...(factory && factoryData ? { factory, factoryData } : {})
|
|
3225
|
+
},
|
|
3226
|
+
chainId,
|
|
3227
|
+
entryPoint
|
|
3228
|
+
};
|
|
3229
|
+
}
|
|
3230
|
+
async signUserOpHash(hash) {
|
|
3231
|
+
const account = this.config.walletClient.account;
|
|
3232
|
+
if (!account)
|
|
3233
|
+
throw new Error('[SmoothSend AVAX] walletClient.account missing');
|
|
3234
|
+
return this.config.walletClient.signMessage({
|
|
3235
|
+
account,
|
|
3236
|
+
message: { raw: hash }
|
|
3237
|
+
});
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3240
|
+
function createSmoothSendAvaxClient(config) {
|
|
3241
|
+
return new SmoothSendAvaxClient(config);
|
|
3242
|
+
}
|
|
3243
|
+
|
|
3040
3244
|
/**
|
|
3041
3245
|
* Public gateway defaults for Avalanche AA (no API key).
|
|
3042
3246
|
*/
|
|
@@ -3233,10 +3437,112 @@ function useSmoothSendAvax(params) {
|
|
|
3233
3437
|
waitForReceipt: args.waitForReceipt,
|
|
3234
3438
|
});
|
|
3235
3439
|
}, [submitCall]);
|
|
3440
|
+
const estimateUserPaysFee = useCallback(async (params) => {
|
|
3441
|
+
if (!publicClient) {
|
|
3442
|
+
throw new Error('[SmoothSend AVAX] publicClient missing (wagmi usePublicClient)');
|
|
3443
|
+
}
|
|
3444
|
+
if (!walletClient) {
|
|
3445
|
+
throw new Error('[SmoothSend AVAX] walletClient missing (wagmi useWalletClient)');
|
|
3446
|
+
}
|
|
3447
|
+
if (!smartAccountAddressProp && !accountFactory) {
|
|
3448
|
+
throw new Error('[SmoothSend AVAX] No smartAccountAddress or accountFactory provided. Pass them to SmoothSendAvaxProvider or useSmoothSendAvax hook.');
|
|
3449
|
+
}
|
|
3450
|
+
const account = walletClient.account;
|
|
3451
|
+
if (!account) {
|
|
3452
|
+
throw new Error('[SmoothSend AVAX] walletClient.account missing — connect wallet (wagmi useWalletClient)');
|
|
3453
|
+
}
|
|
3454
|
+
const ownerAddress = account.address;
|
|
3455
|
+
let sender;
|
|
3456
|
+
if (accountFactory) {
|
|
3457
|
+
const predicted = await predictSimpleAccountAddress({
|
|
3458
|
+
publicClient,
|
|
3459
|
+
factory: accountFactory,
|
|
3460
|
+
owner: ownerAddress,
|
|
3461
|
+
salt: accountSalt,
|
|
3462
|
+
});
|
|
3463
|
+
if (smartAccountAddressProp &&
|
|
3464
|
+
predicted.toLowerCase() !== smartAccountAddressProp.toLowerCase()) {
|
|
3465
|
+
throw new Error(`[SmoothSend AVAX] smartAccountAddress ${smartAccountAddressProp} does not match factory prediction ${predicted}`);
|
|
3466
|
+
}
|
|
3467
|
+
sender = predicted;
|
|
3468
|
+
}
|
|
3469
|
+
else {
|
|
3470
|
+
sender = smartAccountAddressProp;
|
|
3471
|
+
}
|
|
3472
|
+
const entryPoint = (await submitter.getSupportedEntryPoints())[0];
|
|
3473
|
+
const code = await publicClient.getBytecode({ address: sender });
|
|
3474
|
+
const deployed = typeof code === 'string' &&
|
|
3475
|
+
code !== '0x' &&
|
|
3476
|
+
code.length > 2;
|
|
3477
|
+
let nonce;
|
|
3478
|
+
let factory;
|
|
3479
|
+
let factoryData;
|
|
3480
|
+
if (!deployed) {
|
|
3481
|
+
if (!accountFactory) {
|
|
3482
|
+
throw new Error('[SmoothSend AVAX] No bytecode at sender — pass accountFactory so the paymaster can sponsor deploy + call in one UserOp');
|
|
3483
|
+
}
|
|
3484
|
+
nonce = 0n;
|
|
3485
|
+
factory = accountFactory;
|
|
3486
|
+
factoryData = encodeCreateAccountFactoryData(ownerAddress, accountSalt);
|
|
3487
|
+
}
|
|
3488
|
+
else {
|
|
3489
|
+
nonce = await readAvaxSenderNonce({
|
|
3490
|
+
publicClient,
|
|
3491
|
+
entryPointAddress: entryPoint,
|
|
3492
|
+
sender,
|
|
3493
|
+
});
|
|
3494
|
+
}
|
|
3495
|
+
let maxFeePerGas = 50n * 10n ** 9n;
|
|
3496
|
+
let maxPriorityFeePerGas = 2n * 10n ** 9n;
|
|
3497
|
+
try {
|
|
3498
|
+
const est = await publicClient.estimateFeesPerGas();
|
|
3499
|
+
if (est.maxFeePerGas)
|
|
3500
|
+
maxFeePerGas = est.maxFeePerGas;
|
|
3501
|
+
if (est.maxPriorityFeePerGas)
|
|
3502
|
+
maxPriorityFeePerGas = est.maxPriorityFeePerGas;
|
|
3503
|
+
}
|
|
3504
|
+
catch {
|
|
3505
|
+
// ignore and use fallback values
|
|
3506
|
+
}
|
|
3507
|
+
let callData;
|
|
3508
|
+
if (params.calls && params.calls.length > 0) {
|
|
3509
|
+
callData = encodeAvaxExecuteBatchCalldata(params.calls.map(c => c.to), params.calls.map(c => c.value ?? 0n), params.calls.map(c => c.data ?? '0x'));
|
|
3510
|
+
}
|
|
3511
|
+
else {
|
|
3512
|
+
const target = params.call?.to ?? params.to;
|
|
3513
|
+
if (!target)
|
|
3514
|
+
throw new Error('[SmoothSend AVAX] No target address (to) provided');
|
|
3515
|
+
callData = encodeAvaxExecuteCalldata(target, params.call?.value ?? params.value ?? 0n, params.call?.data ?? params.data ?? '0x');
|
|
3516
|
+
}
|
|
3517
|
+
const quote = await submitter.estimateUserPaysFee({
|
|
3518
|
+
userOp: {
|
|
3519
|
+
sender,
|
|
3520
|
+
nonce: toHex(nonce),
|
|
3521
|
+
callData,
|
|
3522
|
+
maxFeePerGas: toHex(maxFeePerGas),
|
|
3523
|
+
maxPriorityFeePerGas: toHex(maxPriorityFeePerGas),
|
|
3524
|
+
...(factory && factoryData ? { factory, factoryData } : {}),
|
|
3525
|
+
},
|
|
3526
|
+
paymaster: params.paymaster,
|
|
3527
|
+
});
|
|
3528
|
+
return {
|
|
3529
|
+
entryPoint: quote.entryPoint,
|
|
3530
|
+
feePreview: quote.feePreview,
|
|
3531
|
+
exchangeRate: quote.exchangeRate,
|
|
3532
|
+
};
|
|
3533
|
+
}, [
|
|
3534
|
+
accountFactory,
|
|
3535
|
+
accountSalt,
|
|
3536
|
+
publicClient,
|
|
3537
|
+
smartAccountAddressProp,
|
|
3538
|
+
submitter,
|
|
3539
|
+
walletClient,
|
|
3540
|
+
]);
|
|
3236
3541
|
return {
|
|
3237
3542
|
submitter,
|
|
3238
3543
|
submitCall,
|
|
3239
3544
|
submitSponsoredUserOp,
|
|
3545
|
+
estimateUserPaysFee,
|
|
3240
3546
|
paymasterAddress,
|
|
3241
3547
|
discoveredFactory: accountFactory ?? null,
|
|
3242
3548
|
};
|
|
@@ -3874,5 +4180,5 @@ if (typeof window !== 'undefined') {
|
|
|
3874
4180
|
' - import { ... } from "@smoothsend/sdk/stellar"');
|
|
3875
4181
|
}
|
|
3876
4182
|
|
|
3877
|
-
export { APTOS_ERROR_CODES, AptosAdapter, AuthenticationError, AvaxSubmitter, CHAIN_ECOSYSTEM_MAP, ENTRY_POINT_V07_ADDRESS, HttpClient, NetworkError, RateLimitError, SIMPLE_ACCOUNT_FACTORY_ABI, STELLAR_ERROR_CODES, ScriptComposerClient, SmoothSendAvaxProvider, SmoothSendAvaxSubmitter, SmoothSendError, SmoothSendSDK, SmoothSendSession, SmoothSendTransactionSubmitter, StellarAdapter, StellarCAddressAdapter, TrueGaslessClient, VERSION, ValidationError, avaxExecuteAbi, createErrorFromResponse, createNetworkError, createScriptComposerClient, createSmoothSendAvaxSubmitter, createSmoothSendSubmitter, createTrueGaslessClient, SmoothSendSDK as default, encodeAvaxExecuteCalldata, encodeCreateAccountFactoryData, fetchAvaxAaPublicDefaults, hashUserOperationAvax, predictSimpleAccountAddress, readAvaxSenderNonce, useSmoothSend, useSmoothSendAvax, useSmoothSendAvaxContext, userOperationAvaxToViem };
|
|
4183
|
+
export { APTOS_ERROR_CODES, AptosAdapter, AuthenticationError, AvaxSubmitter, CHAIN_ECOSYSTEM_MAP, ENTRY_POINT_V07_ADDRESS, HttpClient, NetworkError, RateLimitError, SIMPLE_ACCOUNT_FACTORY_ABI, STELLAR_ERROR_CODES, ScriptComposerClient, SmoothSendAvaxClient, SmoothSendAvaxProvider, SmoothSendAvaxSubmitter, SmoothSendError, SmoothSendSDK, SmoothSendSession, SmoothSendTransactionSubmitter, StellarAdapter, StellarCAddressAdapter, TrueGaslessClient, VERSION, ValidationError, avaxExecuteAbi, createErrorFromResponse, createNetworkError, createScriptComposerClient, createSmoothSendAvaxClient, createSmoothSendAvaxSubmitter, createSmoothSendSubmitter, createTrueGaslessClient, SmoothSendSDK as default, encodeAvaxExecuteCalldata, encodeCreateAccountFactoryData, fetchAvaxAaPublicDefaults, hashUserOperationAvax, predictSimpleAccountAddress, readAvaxSenderNonce, useSmoothSend, useSmoothSendAvax, useSmoothSendAvaxContext, userOperationAvaxToViem };
|
|
3878
4184
|
//# sourceMappingURL=index.js.map
|