@smoothsend/sdk 2.2.11 → 2.3.0
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 +58 -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 +294 -0
- package/dist/avax/index.cjs.map +1 -1
- package/dist/avax/index.d.ts +117 -3
- package/dist/avax/index.d.ts.map +1 -1
- package/dist/avax/index.js +293 -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 +294 -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 +293 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -13,7 +13,7 @@ import { type ReactNode } from 'react';
|
|
|
13
13
|
import type { Address, Hex } from 'viem';
|
|
14
14
|
import type { PublicClient, WalletClient } from 'viem';
|
|
15
15
|
import { SmoothSendAvaxSubmitter } from './SmoothSendAvaxSubmitter';
|
|
16
|
-
import type { AvaxSponsorshipMode, PaymasterSignRequestAvax } from './types';
|
|
16
|
+
import type { AvaxFeePreview, AvaxSponsorshipMode, PaymasterSignRequestAvax } from './types';
|
|
17
17
|
export type SmoothSendAvaxContextValue = {
|
|
18
18
|
apiKey: string;
|
|
19
19
|
network: 'testnet' | 'mainnet';
|
|
@@ -68,5 +68,25 @@ export declare function useSmoothSendAvax(params: UseSmoothSendAvaxParams): {
|
|
|
68
68
|
paymaster?: Omit<PaymasterSignRequestAvax, 'mode' | 'userOp'>;
|
|
69
69
|
waitForReceipt?: boolean;
|
|
70
70
|
}) => ReturnType<SmoothSendAvaxSubmitter['submitSponsoredUserOperation']>;
|
|
71
|
+
estimateUserPaysFee: (args: {
|
|
72
|
+
to?: Address;
|
|
73
|
+
data?: Hex;
|
|
74
|
+
value?: bigint;
|
|
75
|
+
call?: {
|
|
76
|
+
to: Address;
|
|
77
|
+
data?: Hex;
|
|
78
|
+
value?: bigint;
|
|
79
|
+
};
|
|
80
|
+
calls?: {
|
|
81
|
+
to: Address;
|
|
82
|
+
data?: Hex;
|
|
83
|
+
value?: bigint;
|
|
84
|
+
}[];
|
|
85
|
+
paymaster?: Omit<PaymasterSignRequestAvax, 'mode' | 'userOp'>;
|
|
86
|
+
}) => Promise<{
|
|
87
|
+
entryPoint: string;
|
|
88
|
+
feePreview?: AvaxFeePreview;
|
|
89
|
+
exchangeRate?: string;
|
|
90
|
+
}>;
|
|
71
91
|
};
|
|
72
92
|
//# sourceMappingURL=useSmoothSendAvax.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSmoothSendAvax.d.ts","sourceRoot":"","sources":["../../src/avax/useSmoothSendAvax.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useSmoothSendAvax.d.ts","sourceRoot":"","sources":["../../src/avax/useSmoothSendAvax.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OA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AAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QACnD,KAAK,CAAC,EAAE;YAAE,EAAE,EAAE,OAAO,CAAC;YAAC,IAAI,CAAC,EAAE,GAAG,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QACtD,SAAS,CAAC,EAAE,IAAI,CAAC,wBAAwB,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC;KAC/D,KAAK,OAAO,CAAC;QACZ,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,cAAc,CAAC;QAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC,CAAC;CACJ,CAiWA"}
|
package/dist/avax-entry.d.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* const { submitSponsoredUserOp } = useSmoothSendAvax();
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
export { AvaxSubmitter, SmoothSendAvaxSubmitter, createSmoothSendAvaxSubmitter, SmoothSendAvaxProvider, useSmoothSendAvax, useSmoothSendAvaxContext, encodeAvaxExecuteCalldata, hashUserOperationAvax, readAvaxSenderNonce, userOperationAvaxToViem, avaxExecuteAbi, SIMPLE_ACCOUNT_FACTORY_ABI, encodeCreateAccountFactoryData, predictSimpleAccountAddress, ENTRY_POINT_V07_ADDRESS, fetchAvaxAaPublicDefaults, type AvaxAaPublicDefaults, type SmoothSendAvaxSubmitterConfig, type SubmitSponsoredAvaxUserOpOptions, type SmoothSendAvaxContextValue, type UseSmoothSendAvaxParams, type AvaxSponsorshipMode, type GasEstimateAvax, type PaymasterSignRequestAvax, type PaymasterSignResponseAvax, type SponsoredUserOpDraftAvax, type UserOperationAvax, type UserOperationReceiptAvax, } from './avax';
|
|
20
|
+
export { AvaxSubmitter, SmoothSendAvaxClient, SmoothSendAvaxSubmitter, createSmoothSendAvaxClient, createSmoothSendAvaxSubmitter, SmoothSendAvaxProvider, useSmoothSendAvax, useSmoothSendAvaxContext, encodeAvaxExecuteCalldata, hashUserOperationAvax, readAvaxSenderNonce, userOperationAvaxToViem, avaxExecuteAbi, SIMPLE_ACCOUNT_FACTORY_ABI, encodeCreateAccountFactoryData, predictSimpleAccountAddress, ENTRY_POINT_V07_ADDRESS, fetchAvaxAaPublicDefaults, type AvaxAaPublicDefaults, type SmoothSendAvaxSubmitterConfig, type SmoothSendAvaxClientConfig, type SimpleCallInput, type EstimateUserPaysFeeAvaxOptions, type SubmitSponsoredAvaxUserOpOptions, type SmoothSendAvaxContextValue, type UseSmoothSendAvaxParams, type AvaxFeePreview, type AvaxHashTypes, type AvaxSponsorshipMode, type GasEstimateAvax, type PaymasterSignRequestAvax, type PaymasterSignResponseAvax, type SponsoredUserOpDraftAvax, type UserOperationAvax, type UserOperationReceiptAvax, } from './avax';
|
|
21
21
|
export { HttpClient } from './utils/http';
|
|
22
22
|
export { VERSION } from './version';
|
|
23
23
|
export { SmoothSendError } from './types';
|
package/dist/avax-entry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avax-entry.d.ts","sourceRoot":"","sources":["../src/avax-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EACL,aAAa,EACb,uBAAuB,EACvB,6BAA6B,EAC7B,sBAAsB,EACtB,iBAAiB,EACjB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,EACd,0BAA0B,EAC1B,8BAA8B,EAC9B,2BAA2B,EAC3B,uBAAuB,EACvB,yBAAyB,EACzB,KAAK,oBAAoB,EACzB,KAAK,6BAA6B,EAClC,KAAK,gCAAgC,EACrC,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,GAC9B,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"avax-entry.d.ts","sourceRoot":"","sources":["../src/avax-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,EAC1B,6BAA6B,EAC7B,sBAAsB,EACtB,iBAAiB,EACjB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,EACd,0BAA0B,EAC1B,8BAA8B,EAC9B,2BAA2B,EAC3B,uBAAuB,EACvB,yBAAyB,EACzB,KAAK,oBAAoB,EACzB,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACpB,KAAK,8BAA8B,EACnC,KAAK,gCAAgC,EACrC,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,GAC9B,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -2801,6 +2801,38 @@ class SmoothSendAvaxSubmitter {
|
|
|
2801
2801
|
}
|
|
2802
2802
|
return data;
|
|
2803
2803
|
}
|
|
2804
|
+
/**
|
|
2805
|
+
* Preflight fee estimate for `user-pays-erc20` mode.
|
|
2806
|
+
*
|
|
2807
|
+
* This performs:
|
|
2808
|
+
* 1) `eth_estimateUserOperationGas`
|
|
2809
|
+
* 2) `paymaster/sign` in `user-pays-erc20` mode
|
|
2810
|
+
* and returns `feePreview` when available.
|
|
2811
|
+
*/
|
|
2812
|
+
async estimateUserPaysFee(opts) {
|
|
2813
|
+
const entryPoint = opts.entryPoint ?? (await this.getSupportedEntryPoints())[0];
|
|
2814
|
+
if (!entryPoint) {
|
|
2815
|
+
throw new Error('[SmoothSendAvaxSubmitter] no EntryPoint from bundler');
|
|
2816
|
+
}
|
|
2817
|
+
let userOp = {
|
|
2818
|
+
...opts.userOp,
|
|
2819
|
+
signature: opts.userOp.signature ?? '0x',
|
|
2820
|
+
};
|
|
2821
|
+
const gas = await this.estimateUserOperationGas(userOp, entryPoint);
|
|
2822
|
+
userOp = SmoothSendAvaxSubmitter.applyGasEstimate(userOp, gas);
|
|
2823
|
+
const signedPm = await this.paymasterSign({
|
|
2824
|
+
mode: 'user-pays-erc20',
|
|
2825
|
+
userOp,
|
|
2826
|
+
...opts.paymaster,
|
|
2827
|
+
});
|
|
2828
|
+
return {
|
|
2829
|
+
entryPoint,
|
|
2830
|
+
userOp,
|
|
2831
|
+
gas,
|
|
2832
|
+
exchangeRate: signedPm.exchangeRate,
|
|
2833
|
+
feePreview: signedPm.feePreview,
|
|
2834
|
+
};
|
|
2835
|
+
}
|
|
2804
2836
|
async getBundlerHealth() {
|
|
2805
2837
|
const res = await this.http.get('/api/v1/bundler/health');
|
|
2806
2838
|
if (!res.success)
|
|
@@ -3041,6 +3073,164 @@ function encodeCreateAccountFactoryData(owner, salt) {
|
|
|
3041
3073
|
});
|
|
3042
3074
|
}
|
|
3043
3075
|
|
|
3076
|
+
class SmoothSendAvaxClient {
|
|
3077
|
+
constructor(config) {
|
|
3078
|
+
this.config = config;
|
|
3079
|
+
this.submitter = new SmoothSendAvaxSubmitter({
|
|
3080
|
+
apiKey: config.apiKey,
|
|
3081
|
+
network: config.network,
|
|
3082
|
+
gatewayUrl: config.gatewayUrl,
|
|
3083
|
+
timeout: config.timeout,
|
|
3084
|
+
chain: config.chain,
|
|
3085
|
+
corsOrigin: config.corsOrigin
|
|
3086
|
+
});
|
|
3087
|
+
}
|
|
3088
|
+
async submitCall(args) {
|
|
3089
|
+
return this.submitCalls({
|
|
3090
|
+
calls: [args.call],
|
|
3091
|
+
mode: args.mode,
|
|
3092
|
+
paymaster: args.paymaster,
|
|
3093
|
+
waitForReceipt: args.waitForReceipt
|
|
3094
|
+
});
|
|
3095
|
+
}
|
|
3096
|
+
async submitCalls(args) {
|
|
3097
|
+
if (args.calls.length === 0) {
|
|
3098
|
+
throw new Error('[SmoothSend AVAX] No calls provided');
|
|
3099
|
+
}
|
|
3100
|
+
const built = await this.buildDraft(args.calls);
|
|
3101
|
+
const result = await this.submitter.submitSponsoredUserOperation({
|
|
3102
|
+
userOp: built.userOp,
|
|
3103
|
+
mode: args.mode ?? 'developer-sponsored',
|
|
3104
|
+
paymaster: args.paymaster,
|
|
3105
|
+
waitForReceipt: args.waitForReceipt,
|
|
3106
|
+
signUserOp: async (op) => {
|
|
3107
|
+
const hash = hashUserOperationAvax({
|
|
3108
|
+
chainId: built.chainId,
|
|
3109
|
+
entryPointAddress: built.entryPoint,
|
|
3110
|
+
userOperation: op
|
|
3111
|
+
});
|
|
3112
|
+
return this.signUserOpHash(hash);
|
|
3113
|
+
}
|
|
3114
|
+
});
|
|
3115
|
+
return {
|
|
3116
|
+
userOpHash: result.userOpHash,
|
|
3117
|
+
transactionHash: result.receipt?.receipt?.transactionHash,
|
|
3118
|
+
receipt: result.receipt
|
|
3119
|
+
};
|
|
3120
|
+
}
|
|
3121
|
+
async estimateUserPaysFee(args) {
|
|
3122
|
+
if (args.calls.length === 0) {
|
|
3123
|
+
throw new Error('[SmoothSend AVAX] No calls provided');
|
|
3124
|
+
}
|
|
3125
|
+
const built = await this.buildDraft(args.calls);
|
|
3126
|
+
const estimate = await this.submitter.estimateUserPaysFee({
|
|
3127
|
+
userOp: built.userOp,
|
|
3128
|
+
entryPoint: built.entryPoint,
|
|
3129
|
+
paymaster: args.paymaster
|
|
3130
|
+
});
|
|
3131
|
+
return {
|
|
3132
|
+
feePreview: estimate.feePreview,
|
|
3133
|
+
exchangeRate: estimate.exchangeRate,
|
|
3134
|
+
entryPoint: estimate.entryPoint
|
|
3135
|
+
};
|
|
3136
|
+
}
|
|
3137
|
+
async buildDraft(calls) {
|
|
3138
|
+
const { publicClient, walletClient } = this.config;
|
|
3139
|
+
const account = walletClient.account;
|
|
3140
|
+
if (!account) {
|
|
3141
|
+
throw new Error('[SmoothSend AVAX] walletClient.account missing');
|
|
3142
|
+
}
|
|
3143
|
+
const ownerAddress = account.address;
|
|
3144
|
+
const defaults = await this.submitter.getPublicAaDefaults().catch(() => null);
|
|
3145
|
+
const accountFactory = this.config.accountFactory ??
|
|
3146
|
+
((this.config.network ?? 'testnet') === 'mainnet'
|
|
3147
|
+
? defaults?.simpleAccountFactoryMainnet
|
|
3148
|
+
: defaults?.simpleAccountFactoryFuji) ??
|
|
3149
|
+
undefined;
|
|
3150
|
+
const chainId = Number(publicClient.chain?.id ?? (await publicClient.getChainId()));
|
|
3151
|
+
const entryPoint = (await this.submitter.getSupportedEntryPoints())[0];
|
|
3152
|
+
let sender;
|
|
3153
|
+
if (accountFactory) {
|
|
3154
|
+
const predicted = await predictSimpleAccountAddress({
|
|
3155
|
+
publicClient,
|
|
3156
|
+
factory: accountFactory,
|
|
3157
|
+
owner: ownerAddress,
|
|
3158
|
+
salt: this.config.accountSalt ?? 0n
|
|
3159
|
+
});
|
|
3160
|
+
if (this.config.smartAccountAddress &&
|
|
3161
|
+
predicted.toLowerCase() !== this.config.smartAccountAddress.toLowerCase()) {
|
|
3162
|
+
throw new Error(`[SmoothSend AVAX] smartAccountAddress ${this.config.smartAccountAddress} does not match factory prediction ${predicted}`);
|
|
3163
|
+
}
|
|
3164
|
+
sender = predicted;
|
|
3165
|
+
}
|
|
3166
|
+
else if (this.config.smartAccountAddress) {
|
|
3167
|
+
sender = this.config.smartAccountAddress;
|
|
3168
|
+
}
|
|
3169
|
+
else {
|
|
3170
|
+
throw new Error('[SmoothSend AVAX] Provide smartAccountAddress or accountFactory (or use gateway public defaults).');
|
|
3171
|
+
}
|
|
3172
|
+
const code = await publicClient.getBytecode({ address: sender });
|
|
3173
|
+
const deployed = typeof code === 'string' && code !== '0x' && code.length > 2;
|
|
3174
|
+
let nonce;
|
|
3175
|
+
let factory;
|
|
3176
|
+
let factoryData;
|
|
3177
|
+
if (!deployed) {
|
|
3178
|
+
if (!accountFactory) {
|
|
3179
|
+
throw new Error('[SmoothSend AVAX] Sender is not deployed and no accountFactory available');
|
|
3180
|
+
}
|
|
3181
|
+
nonce = 0n;
|
|
3182
|
+
factory = accountFactory;
|
|
3183
|
+
factoryData = encodeCreateAccountFactoryData(ownerAddress, this.config.accountSalt ?? 0n);
|
|
3184
|
+
}
|
|
3185
|
+
else {
|
|
3186
|
+
nonce = await readAvaxSenderNonce({
|
|
3187
|
+
publicClient,
|
|
3188
|
+
entryPointAddress: entryPoint,
|
|
3189
|
+
sender
|
|
3190
|
+
});
|
|
3191
|
+
}
|
|
3192
|
+
let maxFeePerGas = 50n * 10n ** 9n;
|
|
3193
|
+
let maxPriorityFeePerGas = 2n * 10n ** 9n;
|
|
3194
|
+
try {
|
|
3195
|
+
const est = await publicClient.estimateFeesPerGas();
|
|
3196
|
+
if (est.maxFeePerGas)
|
|
3197
|
+
maxFeePerGas = est.maxFeePerGas;
|
|
3198
|
+
if (est.maxPriorityFeePerGas)
|
|
3199
|
+
maxPriorityFeePerGas = est.maxPriorityFeePerGas;
|
|
3200
|
+
}
|
|
3201
|
+
catch {
|
|
3202
|
+
// ignore and use fallbacks
|
|
3203
|
+
}
|
|
3204
|
+
const callData = calls.length === 1
|
|
3205
|
+
? encodeAvaxExecuteCalldata(calls[0].to, calls[0].value ?? 0n, calls[0].data ?? '0x')
|
|
3206
|
+
: encodeAvaxExecuteBatchCalldata(calls.map((c) => c.to), calls.map((c) => c.value ?? 0n), calls.map((c) => c.data ?? '0x'));
|
|
3207
|
+
return {
|
|
3208
|
+
userOp: {
|
|
3209
|
+
sender,
|
|
3210
|
+
nonce: viem.toHex(nonce),
|
|
3211
|
+
callData,
|
|
3212
|
+
maxFeePerGas: viem.toHex(maxFeePerGas),
|
|
3213
|
+
maxPriorityFeePerGas: viem.toHex(maxPriorityFeePerGas),
|
|
3214
|
+
...(factory && factoryData ? { factory, factoryData } : {})
|
|
3215
|
+
},
|
|
3216
|
+
chainId,
|
|
3217
|
+
entryPoint
|
|
3218
|
+
};
|
|
3219
|
+
}
|
|
3220
|
+
async signUserOpHash(hash) {
|
|
3221
|
+
const account = this.config.walletClient.account;
|
|
3222
|
+
if (!account)
|
|
3223
|
+
throw new Error('[SmoothSend AVAX] walletClient.account missing');
|
|
3224
|
+
return this.config.walletClient.signMessage({
|
|
3225
|
+
account,
|
|
3226
|
+
message: { raw: hash }
|
|
3227
|
+
});
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
function createSmoothSendAvaxClient(config) {
|
|
3231
|
+
return new SmoothSendAvaxClient(config);
|
|
3232
|
+
}
|
|
3233
|
+
|
|
3044
3234
|
/**
|
|
3045
3235
|
* Public gateway defaults for Avalanche AA (no API key).
|
|
3046
3236
|
*/
|
|
@@ -3237,10 +3427,112 @@ function useSmoothSendAvax(params) {
|
|
|
3237
3427
|
waitForReceipt: args.waitForReceipt,
|
|
3238
3428
|
});
|
|
3239
3429
|
}, [submitCall]);
|
|
3430
|
+
const estimateUserPaysFee = react.useCallback(async (params) => {
|
|
3431
|
+
if (!publicClient) {
|
|
3432
|
+
throw new Error('[SmoothSend AVAX] publicClient missing (wagmi usePublicClient)');
|
|
3433
|
+
}
|
|
3434
|
+
if (!walletClient) {
|
|
3435
|
+
throw new Error('[SmoothSend AVAX] walletClient missing (wagmi useWalletClient)');
|
|
3436
|
+
}
|
|
3437
|
+
if (!smartAccountAddressProp && !accountFactory) {
|
|
3438
|
+
throw new Error('[SmoothSend AVAX] No smartAccountAddress or accountFactory provided. Pass them to SmoothSendAvaxProvider or useSmoothSendAvax hook.');
|
|
3439
|
+
}
|
|
3440
|
+
const account = walletClient.account;
|
|
3441
|
+
if (!account) {
|
|
3442
|
+
throw new Error('[SmoothSend AVAX] walletClient.account missing — connect wallet (wagmi useWalletClient)');
|
|
3443
|
+
}
|
|
3444
|
+
const ownerAddress = account.address;
|
|
3445
|
+
let sender;
|
|
3446
|
+
if (accountFactory) {
|
|
3447
|
+
const predicted = await predictSimpleAccountAddress({
|
|
3448
|
+
publicClient,
|
|
3449
|
+
factory: accountFactory,
|
|
3450
|
+
owner: ownerAddress,
|
|
3451
|
+
salt: accountSalt,
|
|
3452
|
+
});
|
|
3453
|
+
if (smartAccountAddressProp &&
|
|
3454
|
+
predicted.toLowerCase() !== smartAccountAddressProp.toLowerCase()) {
|
|
3455
|
+
throw new Error(`[SmoothSend AVAX] smartAccountAddress ${smartAccountAddressProp} does not match factory prediction ${predicted}`);
|
|
3456
|
+
}
|
|
3457
|
+
sender = predicted;
|
|
3458
|
+
}
|
|
3459
|
+
else {
|
|
3460
|
+
sender = smartAccountAddressProp;
|
|
3461
|
+
}
|
|
3462
|
+
const entryPoint = (await submitter.getSupportedEntryPoints())[0];
|
|
3463
|
+
const code = await publicClient.getBytecode({ address: sender });
|
|
3464
|
+
const deployed = typeof code === 'string' &&
|
|
3465
|
+
code !== '0x' &&
|
|
3466
|
+
code.length > 2;
|
|
3467
|
+
let nonce;
|
|
3468
|
+
let factory;
|
|
3469
|
+
let factoryData;
|
|
3470
|
+
if (!deployed) {
|
|
3471
|
+
if (!accountFactory) {
|
|
3472
|
+
throw new Error('[SmoothSend AVAX] No bytecode at sender — pass accountFactory so the paymaster can sponsor deploy + call in one UserOp');
|
|
3473
|
+
}
|
|
3474
|
+
nonce = 0n;
|
|
3475
|
+
factory = accountFactory;
|
|
3476
|
+
factoryData = encodeCreateAccountFactoryData(ownerAddress, accountSalt);
|
|
3477
|
+
}
|
|
3478
|
+
else {
|
|
3479
|
+
nonce = await readAvaxSenderNonce({
|
|
3480
|
+
publicClient,
|
|
3481
|
+
entryPointAddress: entryPoint,
|
|
3482
|
+
sender,
|
|
3483
|
+
});
|
|
3484
|
+
}
|
|
3485
|
+
let maxFeePerGas = 50n * 10n ** 9n;
|
|
3486
|
+
let maxPriorityFeePerGas = 2n * 10n ** 9n;
|
|
3487
|
+
try {
|
|
3488
|
+
const est = await publicClient.estimateFeesPerGas();
|
|
3489
|
+
if (est.maxFeePerGas)
|
|
3490
|
+
maxFeePerGas = est.maxFeePerGas;
|
|
3491
|
+
if (est.maxPriorityFeePerGas)
|
|
3492
|
+
maxPriorityFeePerGas = est.maxPriorityFeePerGas;
|
|
3493
|
+
}
|
|
3494
|
+
catch {
|
|
3495
|
+
// ignore and use fallback values
|
|
3496
|
+
}
|
|
3497
|
+
let callData;
|
|
3498
|
+
if (params.calls && params.calls.length > 0) {
|
|
3499
|
+
callData = encodeAvaxExecuteBatchCalldata(params.calls.map(c => c.to), params.calls.map(c => c.value ?? 0n), params.calls.map(c => c.data ?? '0x'));
|
|
3500
|
+
}
|
|
3501
|
+
else {
|
|
3502
|
+
const target = params.call?.to ?? params.to;
|
|
3503
|
+
if (!target)
|
|
3504
|
+
throw new Error('[SmoothSend AVAX] No target address (to) provided');
|
|
3505
|
+
callData = encodeAvaxExecuteCalldata(target, params.call?.value ?? params.value ?? 0n, params.call?.data ?? params.data ?? '0x');
|
|
3506
|
+
}
|
|
3507
|
+
const quote = await submitter.estimateUserPaysFee({
|
|
3508
|
+
userOp: {
|
|
3509
|
+
sender,
|
|
3510
|
+
nonce: viem.toHex(nonce),
|
|
3511
|
+
callData,
|
|
3512
|
+
maxFeePerGas: viem.toHex(maxFeePerGas),
|
|
3513
|
+
maxPriorityFeePerGas: viem.toHex(maxPriorityFeePerGas),
|
|
3514
|
+
...(factory && factoryData ? { factory, factoryData } : {}),
|
|
3515
|
+
},
|
|
3516
|
+
paymaster: params.paymaster,
|
|
3517
|
+
});
|
|
3518
|
+
return {
|
|
3519
|
+
entryPoint: quote.entryPoint,
|
|
3520
|
+
feePreview: quote.feePreview,
|
|
3521
|
+
exchangeRate: quote.exchangeRate,
|
|
3522
|
+
};
|
|
3523
|
+
}, [
|
|
3524
|
+
accountFactory,
|
|
3525
|
+
accountSalt,
|
|
3526
|
+
publicClient,
|
|
3527
|
+
smartAccountAddressProp,
|
|
3528
|
+
submitter,
|
|
3529
|
+
walletClient,
|
|
3530
|
+
]);
|
|
3240
3531
|
return {
|
|
3241
3532
|
submitter,
|
|
3242
3533
|
submitCall,
|
|
3243
3534
|
submitSponsoredUserOp,
|
|
3535
|
+
estimateUserPaysFee,
|
|
3244
3536
|
paymasterAddress,
|
|
3245
3537
|
discoveredFactory: accountFactory ?? null,
|
|
3246
3538
|
};
|
|
@@ -3890,6 +4182,7 @@ exports.RateLimitError = RateLimitError;
|
|
|
3890
4182
|
exports.SIMPLE_ACCOUNT_FACTORY_ABI = SIMPLE_ACCOUNT_FACTORY_ABI;
|
|
3891
4183
|
exports.STELLAR_ERROR_CODES = STELLAR_ERROR_CODES;
|
|
3892
4184
|
exports.ScriptComposerClient = ScriptComposerClient;
|
|
4185
|
+
exports.SmoothSendAvaxClient = SmoothSendAvaxClient;
|
|
3893
4186
|
exports.SmoothSendAvaxProvider = SmoothSendAvaxProvider;
|
|
3894
4187
|
exports.SmoothSendAvaxSubmitter = SmoothSendAvaxSubmitter;
|
|
3895
4188
|
exports.SmoothSendError = SmoothSendError;
|
|
@@ -3905,6 +4198,7 @@ exports.avaxExecuteAbi = avaxExecuteAbi;
|
|
|
3905
4198
|
exports.createErrorFromResponse = createErrorFromResponse;
|
|
3906
4199
|
exports.createNetworkError = createNetworkError;
|
|
3907
4200
|
exports.createScriptComposerClient = createScriptComposerClient;
|
|
4201
|
+
exports.createSmoothSendAvaxClient = createSmoothSendAvaxClient;
|
|
3908
4202
|
exports.createSmoothSendAvaxSubmitter = createSmoothSendAvaxSubmitter;
|
|
3909
4203
|
exports.createSmoothSendSubmitter = createSmoothSendSubmitter;
|
|
3910
4204
|
exports.createTrueGaslessClient = createTrueGaslessClient;
|