@gelatocloud/gasless 0.0.1 → 0.0.3
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/LICENSE +21 -0
- package/README.md +417 -0
- package/_dist/account/actions/sendTransactionSync.d.ts +2 -2
- package/_dist/account/actions/sendTransactionSync.d.ts.map +1 -1
- package/_dist/account/actions/sendTransactionSync.js.map +1 -1
- package/_dist/account/index.d.ts +3 -3
- package/_dist/account/index.d.ts.map +1 -1
- package/_dist/account/index.js +1 -0
- package/_dist/account/index.js.map +1 -1
- package/_dist/relayer/evm/actions/getStatus.d.ts +77 -0
- package/_dist/relayer/evm/actions/getStatus.d.ts.map +1 -1
- package/_dist/relayer/evm/actions/getStatus.js +7 -1
- package/_dist/relayer/evm/actions/getStatus.js.map +1 -1
- package/_dist/relayer/evm/actions/handleTerminalStatus.d.ts +3 -0
- package/_dist/relayer/evm/actions/handleTerminalStatus.d.ts.map +1 -0
- package/_dist/relayer/evm/actions/handleTerminalStatus.js +29 -0
- package/_dist/relayer/evm/actions/handleTerminalStatus.js.map +1 -0
- package/_dist/relayer/evm/actions/index.d.ts +1 -0
- package/_dist/relayer/evm/actions/index.d.ts.map +1 -1
- package/_dist/relayer/evm/actions/index.js +1 -0
- package/_dist/relayer/evm/actions/index.js.map +1 -1
- package/_dist/relayer/evm/actions/sendTransactionSync.d.ts +2 -2
- package/_dist/relayer/evm/actions/sendTransactionSync.d.ts.map +1 -1
- package/_dist/relayer/evm/actions/sendTransactionSync.js +3 -1
- package/_dist/relayer/evm/actions/sendTransactionSync.js.map +1 -1
- package/_dist/relayer/evm/actions/waitForInclusion.d.ts +4 -0
- package/_dist/relayer/evm/actions/waitForInclusion.d.ts.map +1 -0
- package/_dist/relayer/evm/actions/waitForInclusion.js +11 -0
- package/_dist/relayer/evm/actions/waitForInclusion.js.map +1 -0
- package/_dist/relayer/evm/errors/index.d.ts +36 -0
- package/_dist/relayer/evm/errors/index.d.ts.map +1 -0
- package/_dist/relayer/evm/errors/index.js +62 -0
- package/_dist/relayer/evm/errors/index.js.map +1 -0
- package/_dist/relayer/evm/index.d.ts +3 -2
- package/_dist/relayer/evm/index.d.ts.map +1 -1
- package/_dist/relayer/evm/index.js +1 -0
- package/_dist/relayer/evm/index.js.map +1 -1
- package/_dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +6 -1
- package/CHANGELOG.md +0 -9
- package/account/actions/getFeeQuote.ts +0 -34
- package/account/actions/index.ts +0 -3
- package/account/actions/sendTransaction.ts +0 -61
- package/account/actions/sendTransactionSync.ts +0 -51
- package/account/adapters/gelato/abi.ts +0 -13
- package/account/adapters/gelato/constants.ts +0 -13
- package/account/adapters/gelato/index.ts +0 -216
- package/account/adapters/index.ts +0 -1
- package/account/adapters/types/index.ts +0 -36
- package/account/index.ts +0 -60
- package/account/utils/delegation.ts +0 -9
- package/account/utils/estimation.ts +0 -29
- package/account/utils/index.ts +0 -2
- package/bundler/actions/estimateUserOperationGas.ts +0 -63
- package/bundler/actions/getUserOperationGasPrice.ts +0 -25
- package/bundler/actions/getUserOperationQuote.ts +0 -83
- package/bundler/actions/index.ts +0 -6
- package/bundler/actions/prepareUserOperation.ts +0 -437
- package/bundler/actions/sendUserOperation.ts +0 -64
- package/bundler/actions/sendUserOperationSync.ts +0 -71
- package/bundler/index.ts +0 -98
- package/constants/index.ts +0 -2
- package/index.ts +0 -4
- package/relayer/evm/actions/getCapabilities.ts +0 -22
- package/relayer/evm/actions/getFeeData.ts +0 -36
- package/relayer/evm/actions/getFeeQuote.ts +0 -39
- package/relayer/evm/actions/getGelatoStatus.ts +0 -99
- package/relayer/evm/actions/getStatus.ts +0 -92
- package/relayer/evm/actions/index.ts +0 -9
- package/relayer/evm/actions/sendTransaction.ts +0 -33
- package/relayer/evm/actions/sendTransactionSync.ts +0 -30
- package/relayer/evm/actions/waitForGelatoStatus.ts +0 -28
- package/relayer/evm/actions/waitForStatus.ts +0 -24
- package/relayer/evm/index.ts +0 -77
- package/relayer/index.ts +0 -1
- package/tsconfig.build.json +0 -19
- package/tsconfig.json +0 -8
- package/types/error.ts +0 -38
- package/types/index.ts +0 -3
- package/types/payment.ts +0 -23
- package/types/schema.ts +0 -28
- package/utils/index.ts +0 -2
- package/utils/payment.ts +0 -20
- package/utils/serialize.ts +0 -91
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gelatocloud/gasless",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"author": "Gelato",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"description": "Gelato Gasless SDK: All-in-one solution for gasless transactions",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
@@ -22,6 +23,10 @@
|
|
|
22
23
|
"default": "./_dist/index.js"
|
|
23
24
|
}
|
|
24
25
|
},
|
|
26
|
+
"files": [
|
|
27
|
+
"_dist",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
25
30
|
"dependencies": {
|
|
26
31
|
"zod": "4.1.13"
|
|
27
32
|
},
|
package/CHANGELOG.md
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { type Call, zeroAddress } from 'viem';
|
|
2
|
-
import type { SmartAccount } from 'viem/account-abstraction';
|
|
3
|
-
import type { CapabilitiesByChain, FeeQuote, GelatoEvmRelayerClient } from '../../relayer/index.js';
|
|
4
|
-
import { type Payment, PaymentType } from '../../types/index.js';
|
|
5
|
-
import { appendPayment } from '../../utils/index.js';
|
|
6
|
-
import type { GelatoSmartAccountImplementation } from '../adapters/types/index.js';
|
|
7
|
-
|
|
8
|
-
export type GetFeeQuoteParameters = {
|
|
9
|
-
payment: Payment;
|
|
10
|
-
calls: Call[];
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const getFeeQuote = async (
|
|
14
|
-
client: GelatoEvmRelayerClient,
|
|
15
|
-
account: SmartAccount<GelatoSmartAccountImplementation>,
|
|
16
|
-
capabilities: CapabilitiesByChain,
|
|
17
|
-
parameters: GetFeeQuoteParameters
|
|
18
|
-
): Promise<FeeQuote> => {
|
|
19
|
-
const { payment } = parameters;
|
|
20
|
-
|
|
21
|
-
const calls =
|
|
22
|
-
payment.type === PaymentType.Token
|
|
23
|
-
? appendPayment(parameters.calls, payment.address, capabilities.feeCollector, 1n)
|
|
24
|
-
: parameters.calls;
|
|
25
|
-
|
|
26
|
-
const { estimatedGas, estimatedL1Fee } = await account.estimate({ calls });
|
|
27
|
-
|
|
28
|
-
return await client.getFeeQuote({
|
|
29
|
-
chainId: account.chain.id,
|
|
30
|
-
gas: estimatedGas,
|
|
31
|
-
l1Fee: estimatedL1Fee,
|
|
32
|
-
token: payment.type === PaymentType.Token ? payment.address : zeroAddress
|
|
33
|
-
});
|
|
34
|
-
};
|
package/account/actions/index.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { Hex } from 'viem';
|
|
2
|
-
import type { SmartAccount } from 'viem/account-abstraction';
|
|
3
|
-
import type { CapabilitiesByChain, FeeQuote, GelatoEvmRelayerClient } from '../../relayer/index.js';
|
|
4
|
-
import { PaymentType } from '../../types/index.js';
|
|
5
|
-
import { appendPayment } from '../../utils/index.js';
|
|
6
|
-
import type { GelatoSmartAccountImplementation } from '../adapters/types/index.js';
|
|
7
|
-
import { type GetFeeQuoteParameters, getFeeQuote } from './getFeeQuote.js';
|
|
8
|
-
|
|
9
|
-
export type NonceOrKey =
|
|
10
|
-
| {
|
|
11
|
-
nonce?: never;
|
|
12
|
-
nonceKey?: never;
|
|
13
|
-
}
|
|
14
|
-
| {
|
|
15
|
-
nonce: bigint;
|
|
16
|
-
nonceKey?: never;
|
|
17
|
-
}
|
|
18
|
-
| {
|
|
19
|
-
nonce?: never;
|
|
20
|
-
nonceKey: bigint;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type SendTransactionParameters = GetFeeQuoteParameters &
|
|
24
|
-
NonceOrKey & {
|
|
25
|
-
quote?: FeeQuote;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const sendTransaction = async (
|
|
29
|
-
client: GelatoEvmRelayerClient,
|
|
30
|
-
account: SmartAccount<GelatoSmartAccountImplementation>,
|
|
31
|
-
capabilities: CapabilitiesByChain,
|
|
32
|
-
parameters: SendTransactionParameters
|
|
33
|
-
): Promise<Hex> => {
|
|
34
|
-
const { payment } = parameters;
|
|
35
|
-
|
|
36
|
-
const [quote, nonce, deployed] = await Promise.all([
|
|
37
|
-
payment.type === PaymentType.Token
|
|
38
|
-
? (parameters.quote ?? (await getFeeQuote(client, account, capabilities, parameters)))
|
|
39
|
-
: undefined,
|
|
40
|
-
parameters.nonce ?? account.getNonce({ key: parameters.nonceKey }),
|
|
41
|
-
account.isDeployed()
|
|
42
|
-
]);
|
|
43
|
-
|
|
44
|
-
const calls = quote
|
|
45
|
-
? appendPayment(parameters.calls, quote.token.address, capabilities.feeCollector, quote.fee)
|
|
46
|
-
: parameters.calls;
|
|
47
|
-
|
|
48
|
-
const [data, authorizationList] = await Promise.all([
|
|
49
|
-
account.encodeCallData({ calls, nonce }),
|
|
50
|
-
deployed ? undefined : account.signAuthorization().then((x) => [x])
|
|
51
|
-
]);
|
|
52
|
-
|
|
53
|
-
return await client.sendTransaction({
|
|
54
|
-
authorizationList,
|
|
55
|
-
chainId: account.chain.id,
|
|
56
|
-
context: quote?.context,
|
|
57
|
-
data,
|
|
58
|
-
payment,
|
|
59
|
-
to: account.address
|
|
60
|
-
});
|
|
61
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { SmartAccount } from 'viem/account-abstraction';
|
|
2
|
-
import type {
|
|
3
|
-
CapabilitiesByChain,
|
|
4
|
-
GelatoEvmRelayerClient,
|
|
5
|
-
TerminalStatus
|
|
6
|
-
} from '../../relayer/index.js';
|
|
7
|
-
import { PaymentType } from '../../types/index.js';
|
|
8
|
-
import { appendPayment } from '../../utils/index.js';
|
|
9
|
-
import type { GelatoSmartAccountImplementation } from '../adapters/types/index.js';
|
|
10
|
-
import { getFeeQuote } from './getFeeQuote.js';
|
|
11
|
-
import type { SendTransactionParameters } from './sendTransaction.js';
|
|
12
|
-
|
|
13
|
-
export type SendTransactionSyncParameters = SendTransactionParameters & {
|
|
14
|
-
timeout?: number;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const sendTransactionSync = async (
|
|
18
|
-
client: GelatoEvmRelayerClient,
|
|
19
|
-
account: SmartAccount<GelatoSmartAccountImplementation>,
|
|
20
|
-
capabilities: CapabilitiesByChain,
|
|
21
|
-
parameters: SendTransactionSyncParameters
|
|
22
|
-
): Promise<TerminalStatus> => {
|
|
23
|
-
const { payment, timeout } = parameters;
|
|
24
|
-
|
|
25
|
-
const [quote, nonce, deployed] = await Promise.all([
|
|
26
|
-
payment.type === PaymentType.Token
|
|
27
|
-
? (parameters.quote ?? (await getFeeQuote(client, account, capabilities, parameters)))
|
|
28
|
-
: undefined,
|
|
29
|
-
parameters.nonce ?? account.getNonce({ key: parameters.nonceKey }),
|
|
30
|
-
account.isDeployed()
|
|
31
|
-
]);
|
|
32
|
-
|
|
33
|
-
const calls = quote
|
|
34
|
-
? appendPayment(parameters.calls, quote.token.address, capabilities.feeCollector, quote.fee)
|
|
35
|
-
: parameters.calls;
|
|
36
|
-
|
|
37
|
-
const [data, authorizationList] = await Promise.all([
|
|
38
|
-
account.encodeCallData({ calls, nonce }),
|
|
39
|
-
deployed ? undefined : account.signAuthorization().then((x) => [x])
|
|
40
|
-
]);
|
|
41
|
-
|
|
42
|
-
return await client.sendTransactionSync({
|
|
43
|
-
authorizationList,
|
|
44
|
-
chainId: account.chain.id,
|
|
45
|
-
context: quote?.context,
|
|
46
|
-
data,
|
|
47
|
-
payment,
|
|
48
|
-
timeout,
|
|
49
|
-
to: account.address
|
|
50
|
-
});
|
|
51
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { parseAbi } from 'viem';
|
|
2
|
-
|
|
3
|
-
export const delegationAbi = parseAbi([
|
|
4
|
-
'function execute(bytes32 mode, bytes executionData) payable',
|
|
5
|
-
'function getNonce(uint192 key) returns (uint256)'
|
|
6
|
-
]);
|
|
7
|
-
|
|
8
|
-
export const simulationAbi = parseAbi([
|
|
9
|
-
'function simulateExecute(bytes32 mode, bytes executionData)'
|
|
10
|
-
]);
|
|
11
|
-
|
|
12
|
-
export const simulationBytecode =
|
|
13
|
-
'0x6080604052600436106100f4575f3560e01c806384b0196e1161008e578063bc197c8111610060578063bc197c8114610300578063d03c79141461032e578063e9ae5c531461034d578063ebb86b0914610360578063f23a6e611461037357005b806384b0196e1461026d5780638dd7712f14610294578063b0d691fe146102b3578063b70e36f0146102e157005b80633e1b0812116100c75780633e1b0812146101ba57806340a141ff146101d95780634d238c8e146101f857806375f251671461021757005b806301ffc9a7146100f6578063150b7a021461012a5780631626ba7e1461016e57806319822f7c1461018d575b005b348015610101575f5ffd5b5061011561011036600461137f565b61039f565b60405190151581526020015b60405180910390f35b348015610135575f5ffd5b506101556101443660046113f2565b630a85bd0160e11b95945050505050565b6040516001600160e01b03199091168152602001610121565b348015610179575f5ffd5b5061015561018836600461145f565b6103f0565b348015610198575f5ffd5b506101ac6101a73660046114bd565b610506565b604051908152602001610121565b3480156101c5575f5ffd5b506101ac6101d4366004611506565b61070e565b3480156101e4575f5ffd5b506100f46101f336600461152c565b610753565b348015610203575f5ffd5b506100f461021236600461152c565b6107da565b348015610222575f5ffd5b5061011561023136600461152c565b6001600160a01b03165f9081527f1581abf533ae210f1ff5d25f322511179a9a65d8d8e43c998eab264f924af901602052604090205460ff1690565b348015610278575f5ffd5b50610281610864565b6040516101219796959493929190611575565b34801561029f575f5ffd5b506100f46102ae36600461160b565b6108cb565b3480156102be575f5ffd5b50604051734337084d9e255ff0702461cf8895ce9e3b5ff1088152602001610121565b3480156102ec575f5ffd5b506100f46102fb36600461164c565b610986565b34801561030b575f5ffd5b5061015561031a3660046116a3565b63bc197c8160e01b98975050505050505050565b348015610339575f5ffd5b5061011561034836600461164c565b610a6b565b6100f461035b36600461145f565b610af0565b6100f461036e36600461145f565b610b01565b34801561037e575f5ffd5b5061015561038d366004611763565b63f23a6e6160e01b9695505050505050565b5f6001600160e01b031982166301ffc9a760e01b14806103cf57506001600160e01b03198216630a85bd0160e11b145b806103ea57506001600160e01b03198216630271189760e51b145b92915050565b5f604182900361042757610405848484610b0e565b610417576001600160e01b0319610420565b630b135d3f60e11b5b90506104ff565b5f365f6104348686610bfa565b92509250925061044e5f516020611a935f395f51905f5290565b6001600160a01b0384165f908152600191909101602052604090205460ff1661048a57604051631a0a9b9f60e21b815260040160405180910390fd5b604051630b135d3f60e11b81526001600160a01b03841690631626ba7e906104ba908a9086908690600401611801565b602060405180830381865afa1580156104d5573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104f99190611823565b93505050505b9392505050565b5f33734337084d9e255ff0702461cf8895ce9e3b5ff1081461053b576040516348f5c3ed60e01b815260040160405180910390fd5b811561058a576040515f90339084908381818185875af1925050503d805f8114610580576040519150601f19603f3d011682016040523d82523d5f602084013e610585565b606091505b505050505b61059861010085018561183e565b90506041036105cf576105b8836105b361010087018761183e565b610b0e565b6105c35760016105c5565b5f5b60ff1690506104ff565b5f36816105e86105e361010089018961183e565b610bfa565b9250925092506106025f516020611a935f395f51905f5290565b6001600160a01b0384165f908152600191909101602052604090205460ff1661063e57604051631a0a9b9f60e21b815260040160405180910390fd5b6106488684610c0f565b365f61067661065a60608b018b61183e565b610668916004908290611880565b508035016020810191903590565b6040516302cd6e3760e21b815291935091506001600160a01b03861690630b35b8dc906106b1908590859033908e908b908b906004016118a7565b6020604051808303815f875af11580156106cd573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106f191906119b3565b6106fc5760016106fe565b5f5b60ff169998505050505050505050565b6001600160c01b0381165f9081525f516020611a935f395f51905f5260208190526040808320546001600160401b03169084901b67ffffffffffffffff1916176104ff565b333014610773576040516348f5c3ed60e01b815260040160405180910390fd5b6001600160a01b0381165f8181527f1581abf533ae210f1ff5d25f322511179a9a65d8d8e43c998eab264f924af9016020526040808220805460ff19169055517fe1434e25d6611e0db941968fdc97811c982ac1602e951637d206f5fdda9dd8f19190a250565b3330146107fa576040516348f5c3ed60e01b815260040160405180910390fd5b6001600160a01b0381165f8181527f1581abf533ae210f1ff5d25f322511179a9a65d8d8e43c998eab264f924af9016020526040808220805460ff19166001179055517fe366c1c0452ed8eec96861e9e54141ebff23c9ec89fe27b996b45f5ec38849879190a250565b600f60f81b6060805f8080836108b9604080518082018252601081526f23b2b630ba37a232b632b3b0ba34b7b760811b60208083019190915282518084019093526005835264302e302e3160d81b9083015291565b97989097965046955030945091925090565b33734337084d9e255ff0702461cf8895ce9e3b5ff108146108ff576040516348f5c3ed60e01b815260040160405180910390fd5b365f61091161065a606086018661183e565b9150915061091f8282610c16565b825c6001600160a01b0381161561097f57806001600160a01b031663e2778fd96040518163ffffffff1660e01b81526004015f604051808303815f87803b158015610968575f5ffd5b505af115801561097a573d5f5f3e3d5ffd5b505050505b5050505050565b3330146109a6576040516348f5c3ed60e01b815260040160405180910390fd5b604081811c5f8181525f516020611a935f395f51905f52602052919091205482906001600160401b0390811690821681106109f457604051633ab3447f60e11b815260040160405180910390fd5b80820361ffff6001600160401b0382161115610a2357604051631269ad1360e11b815260040160405180910390fd5b50506001600160c01b03919091165f9081525f516020611a935f395f51905f5260205260409020805467ffffffffffffffff19166001600160401b0390921691909117905550565b5f81600881901b603082901b600160f81b6001600160f81b03198416141580610a9d57506001600160f81b0319821615155b15610aac57505f949350505050565b6001600160e01b0319811615801590610ad657506001600160e01b03198116637821000160e01b14155b15610ae557505f949350505050565b506001949350505050565b610afc8383835f610d07565b505050565b610afc8383836001610d07565b5f823560208401356040850135831a7f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0821115610b5e576040516317e97eb760e31b815260040160405180910390fd5b604080515f808252602082018084528a905260ff841692820192909252606081018590526080810184905260019060a0016020604051602081039080840390855afa158015610baf573d5f5f3e3d5ffd5b5050604051601f1901519150506001600160a01b038116610be357604051638baa579f60e01b815260040160405180910390fd5b6001600160a01b0316301493505050509392505050565b813560601c9260149092019160131990910190565b80825d5050565b5f5b81811015610afc5736838383818110610c3357610c336119d2565b9050602002810190610c4591906119e6565b90505f80610c56602084018461152c565b6001600160a01b031614610c7657610c71602083018361152c565b610c78565b305b90505f806001600160a01b0383166020850135610c98604087018761183e565b604051610ca6929190611a04565b5f6040518083038185875af1925050503d805f8114610ce0576040519150601f19603f3d011682016040523d82523d5f602084013e610ce5565b606091505b509150915081610cf757805160208201fd5b505060019092019150610c189050565b83600881901b603082901b600160f81b6001600160f81b03198416141580610d3857506001600160f81b0319821615155b15610d5657604051637f18127560e01b815260040160405180910390fd5b853586016020810190356001600160e01b03198316610d9d57333014610d8e576040516282b42960e81b815260040160405180910390fd5b610d988282610c16565b61097a565b6387deffff60e01b6001600160e01b0319841601610f9e5760208881013589019081019080359060380160171982015f610dda853560401c610fb7565b90505f610de98f89898561103a565b90506041839003610e3657610dff818585610b0e565b158015610e0a57508b155b15610e27576040516282b42960e81b815260040160405180910390fd5b610e318888610c16565b610f93565b5f365f610e438787610bfa565b925092509250610e5d5f516020611a935f395f51905f5290565b6001600160a01b0384165f908152600191909101602052604090205460ff16610e9957604051631a0a9b9f60e21b815260040160405180910390fd5b6040516302cd6e3760e21b81526001600160a01b03841690630b35b8dc90610ecf908e908e9033908a90899089906004016118a7565b6020604051808303815f875af1158015610eeb573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f0f91906119b3565b158015610f1a57508e155b15610f37576040516282b42960e81b815260040160405180910390fd5b610f418b8b610c16565b826001600160a01b031663e2778fd96040518163ffffffff1660e01b81526004015f604051808303815f87803b158015610f79575f5ffd5b505af1158015610f8b573d5f5f3e3d5ffd5b505050505050505b50505050505061097a565b604051637f18127560e01b815260040160405180910390fd5b6001600160c01b0381165f9081525f516020611a935f395f51905f526020526040812080546001600160401b031690819083610ff283611a13565b91906101000a8154816001600160401b0302191690836001600160401b03160217905550506104ff83826001600160401b031660409190911b67ffffffffffffffff19161790565b5f80836001600160401b0381111561105457611054611a49565b60405190808252806020026020018201604052801561107d578160200160208202803683370190505b5090505f5b848110156111b7577f9085b19ea56248c94d86174b3784cfaaa8673d1041d6441f61ff52752dac84838686838181106110bd576110bd6119d2565b90506020028101906110cf91906119e6565b6110dd90602081019061152c565b8787848181106110ef576110ef6119d2565b905060200281019061110191906119e6565b60200135888885818110611117576111176119d2565b905060200281019061112991906119e6565b61113790604081019061183e565b604051611145929190611a04565b60405190819003812061117c949392916020019384526001600160a01b039290921660208401526040830152606082015260800190565b604051602081830303815290604052805190602001208282815181106111a4576111a46119d2565b6020908102919091010152600101611082565b505f7fdf21343e200fb58137ad2784f9ea58605ec77f388015dc495486275b8eec47da5f1b87836040516020016111ee9190611a5d565b60408051601f1981840301815282825280516020918201209083019490945281019190915260608101919091526080810185905260a00160405160208183030381529060405280519060200120905061124681611251565b979650505050505050565b7f00000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000030147f00000000000000000000000000000000000000000000000000000000000000004614166113445750604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f81527f000000000000000000000000000000000000000000000000000000000000000060208201527f00000000000000000000000000000000000000000000000000000000000000009181019190915246606082015230608082015260a090205b6719010000000000005f5280601a5281603a52604260182090505f603a52919050565b6001600160e01b03198116811461137c575f5ffd5b50565b5f6020828403121561138f575f5ffd5b81356104ff81611367565b6001600160a01b038116811461137c575f5ffd5b5f5f83601f8401126113be575f5ffd5b5081356001600160401b038111156113d4575f5ffd5b6020830191508360208285010111156113eb575f5ffd5b9250929050565b5f5f5f5f5f60808688031215611406575f5ffd5b85356114118161139a565b945060208601356114218161139a565b93506040860135925060608601356001600160401b03811115611442575f5ffd5b61144e888289016113ae565b969995985093965092949392505050565b5f5f5f60408486031215611471575f5ffd5b8335925060208401356001600160401b0381111561148d575f5ffd5b611499868287016113ae565b9497909650939450505050565b5f61012082840312156114b7575f5ffd5b50919050565b5f5f5f606084860312156114cf575f5ffd5b83356001600160401b038111156114e4575f5ffd5b6114f0868287016114a6565b9660208601359650604090950135949350505050565b5f60208284031215611516575f5ffd5b81356001600160c01b03811681146104ff575f5ffd5b5f6020828403121561153c575f5ffd5b81356104ff8161139a565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b60ff60f81b8816815260e060208201525f61159360e0830189611547565b82810360408401526115a58189611547565b606084018890526001600160a01b038716608085015260a0840186905283810360c0850152845180825260208087019350909101905f5b818110156115fa5783518352602093840193909201916001016115dc565b50909b9a5050505050505050505050565b5f5f6040838503121561161c575f5ffd5b82356001600160401b03811115611631575f5ffd5b61163d858286016114a6565b95602094909401359450505050565b5f6020828403121561165c575f5ffd5b5035919050565b5f5f83601f840112611673575f5ffd5b5081356001600160401b03811115611689575f5ffd5b6020830191508360208260051b85010111156113eb575f5ffd5b5f5f5f5f5f5f5f5f60a0898b0312156116ba575f5ffd5b88356116c58161139a565b975060208901356116d58161139a565b965060408901356001600160401b038111156116ef575f5ffd5b6116fb8b828c01611663565b90975095505060608901356001600160401b03811115611719575f5ffd5b6117258b828c01611663565b90955093505060808901356001600160401b03811115611743575f5ffd5b61174f8b828c016113ae565b999c989b5096995094979396929594505050565b5f5f5f5f5f5f60a08789031215611778575f5ffd5b86356117838161139a565b955060208701356117938161139a565b9450604087013593506060870135925060808701356001600160401b038111156117bb575f5ffd5b6117c789828a016113ae565b979a9699509497509295939492505050565b81835281816020850137505f828201602090810191909152601f909101601f19169091010190565b838152604060208201525f61181a6040830184866117d9565b95945050505050565b5f60208284031215611833575f5ffd5b81516104ff81611367565b5f5f8335601e19843603018112611853575f5ffd5b8301803591506001600160401b0382111561186c575f5ffd5b6020019150368190038213156113eb575f5ffd5b5f5f8585111561188e575f5ffd5b8386111561189a575f5ffd5b5050820193919092039150565b608080825281018690525f60a0600588901b830181019083018983605e1936839003015b8b82101561197a57868503609f1901845282358181126118e9575f5ffd5b8d0180356118f68161139a565b6001600160a01b0316865260208181013590870152604081013536829003601e19018112611922575f5ffd5b016020810190356001600160401b0381111561193c575f5ffd5b80360382131561194a575f5ffd5b6060604088015261195f6060880182846117d9565b965050506020830192506020840193506001820191506118cb565b5050506001600160a01b03881660208501525085604084015282810360608401526119a68185876117d9565b9998505050505050505050565b5f602082840312156119c3575f5ffd5b815180151581146104ff575f5ffd5b634e487b7160e01b5f52603260045260245ffd5b5f8235605e198336030181126119fa575f5ffd5b9190910192915050565b818382375f9101908152919050565b5f6001600160401b0382166001600160401b038103611a4057634e487b7160e01b5f52601160045260245ffd5b60010192915050565b634e487b7160e01b5f52604160045260245ffd5b81515f90829060208501835b82811015611a87578151845260209384019390910190600101611a69565b50919594505050505056fe1581abf533ae210f1ff5d25f322511179a9a65d8d8e43c998eab264f924af900';
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Address } from 'viem';
|
|
2
|
-
|
|
3
|
-
export const GELATO_DELEGATION_ADDRESS: Address = '0x5aF42746a8Af42d8a4708dF238C53F1F71abF0E0';
|
|
4
|
-
|
|
5
|
-
export const GELATO_DELEGATION_NAME = 'GelatoDelegation';
|
|
6
|
-
|
|
7
|
-
export const GELATO_DELEGATION_VERSION = '0.0.1';
|
|
8
|
-
|
|
9
|
-
export const STUB_SIGNATURE =
|
|
10
|
-
'0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c';
|
|
11
|
-
|
|
12
|
-
export const EXECUTION_MODE_OP_DATA =
|
|
13
|
-
'0x0100000000007821000100000000000000000000000000000000000000000000';
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Account,
|
|
3
|
-
type Chain,
|
|
4
|
-
type Client,
|
|
5
|
-
encodeFunctionData,
|
|
6
|
-
encodePacked,
|
|
7
|
-
type JsonRpcAccount,
|
|
8
|
-
type LocalAccount,
|
|
9
|
-
type StateOverride,
|
|
10
|
-
type Transport,
|
|
11
|
-
type TypedDataDefinition
|
|
12
|
-
} from 'viem';
|
|
13
|
-
import {
|
|
14
|
-
entryPoint08Abi,
|
|
15
|
-
entryPoint08Address,
|
|
16
|
-
getUserOperationTypedData,
|
|
17
|
-
type SmartAccount
|
|
18
|
-
} from 'viem/account-abstraction';
|
|
19
|
-
import {
|
|
20
|
-
estimateGas,
|
|
21
|
-
getCode,
|
|
22
|
-
readContract,
|
|
23
|
-
signMessage,
|
|
24
|
-
signTypedData,
|
|
25
|
-
signAuthorization as viem_signAuthorization
|
|
26
|
-
} from 'viem/actions';
|
|
27
|
-
import { encodeCalls } from 'viem/experimental/erc7821';
|
|
28
|
-
import { delegationCode, delegationGas, estimateL1Fee } from '../../utils/index.js';
|
|
29
|
-
import type { GelatoSmartAccountImplementation } from '../types/index.js';
|
|
30
|
-
import { delegationAbi, simulationAbi, simulationBytecode } from './abi.js';
|
|
31
|
-
import {
|
|
32
|
-
EXECUTION_MODE_OP_DATA,
|
|
33
|
-
GELATO_DELEGATION_ADDRESS,
|
|
34
|
-
GELATO_DELEGATION_NAME,
|
|
35
|
-
GELATO_DELEGATION_VERSION,
|
|
36
|
-
STUB_SIGNATURE
|
|
37
|
-
} from './constants.js';
|
|
38
|
-
|
|
39
|
-
export type GelatoSmartAccountParameters = {
|
|
40
|
-
client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;
|
|
41
|
-
owner: Account;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export type GelatoSmartAccountReturnType = SmartAccount<
|
|
45
|
-
GelatoSmartAccountImplementation<typeof entryPoint08Abi, '0.8'>
|
|
46
|
-
>;
|
|
47
|
-
|
|
48
|
-
export const toGelatoSmartAccount = (
|
|
49
|
-
parameters: GelatoSmartAccountParameters
|
|
50
|
-
): GelatoSmartAccountReturnType => {
|
|
51
|
-
const { client, owner } = parameters;
|
|
52
|
-
|
|
53
|
-
let deployed = false;
|
|
54
|
-
const isDeployed = async () => {
|
|
55
|
-
if (deployed) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const code = await getCode(client, { address: owner.address });
|
|
60
|
-
|
|
61
|
-
deployed =
|
|
62
|
-
code !== undefined &&
|
|
63
|
-
code.toLowerCase() === delegationCode(GELATO_DELEGATION_ADDRESS).toLowerCase();
|
|
64
|
-
|
|
65
|
-
return deployed;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const getNonce = async (parameters?: { key?: bigint }) =>
|
|
69
|
-
readContract(client, {
|
|
70
|
-
abi: delegationAbi,
|
|
71
|
-
address: owner.address,
|
|
72
|
-
args: [parameters?.key ?? 0n],
|
|
73
|
-
functionName: 'getNonce',
|
|
74
|
-
stateOverride: (await isDeployed())
|
|
75
|
-
? undefined
|
|
76
|
-
: [
|
|
77
|
-
{
|
|
78
|
-
address: owner.address,
|
|
79
|
-
code: delegationCode(GELATO_DELEGATION_ADDRESS)
|
|
80
|
-
}
|
|
81
|
-
]
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
address: owner.address,
|
|
86
|
-
authorization: {
|
|
87
|
-
account: undefined as never,
|
|
88
|
-
address: GELATO_DELEGATION_ADDRESS
|
|
89
|
-
},
|
|
90
|
-
chain: client.chain,
|
|
91
|
-
client,
|
|
92
|
-
encodeCallData: async (parameters) => {
|
|
93
|
-
const { calls, nonce } = parameters;
|
|
94
|
-
|
|
95
|
-
const signature = await signTypedData(client, {
|
|
96
|
-
account: owner,
|
|
97
|
-
domain: {
|
|
98
|
-
chainId: client.chain.id,
|
|
99
|
-
name: GELATO_DELEGATION_NAME,
|
|
100
|
-
verifyingContract: owner.address,
|
|
101
|
-
version: GELATO_DELEGATION_VERSION
|
|
102
|
-
},
|
|
103
|
-
message: {
|
|
104
|
-
calls: calls.map((call) => ({
|
|
105
|
-
data: call.data ?? '0x',
|
|
106
|
-
to: call.to,
|
|
107
|
-
value: call.value ?? 0n
|
|
108
|
-
})),
|
|
109
|
-
mode: EXECUTION_MODE_OP_DATA,
|
|
110
|
-
nonce
|
|
111
|
-
},
|
|
112
|
-
primaryType: 'Execute',
|
|
113
|
-
types: {
|
|
114
|
-
Call: [
|
|
115
|
-
{ name: 'to', type: 'address' },
|
|
116
|
-
{ name: 'value', type: 'uint256' },
|
|
117
|
-
{ name: 'data', type: 'bytes' }
|
|
118
|
-
],
|
|
119
|
-
Execute: [
|
|
120
|
-
{ name: 'mode', type: 'bytes32' },
|
|
121
|
-
{ name: 'calls', type: 'Call[]' },
|
|
122
|
-
{ name: 'nonce', type: 'uint256' }
|
|
123
|
-
]
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
const nonceKey = nonce >> 64n;
|
|
128
|
-
|
|
129
|
-
const opData = encodePacked(['uint192', 'bytes'], [nonceKey, signature]);
|
|
130
|
-
|
|
131
|
-
return encodeFunctionData({
|
|
132
|
-
abi: delegationAbi,
|
|
133
|
-
args: [EXECUTION_MODE_OP_DATA, encodeCalls(calls, opData)],
|
|
134
|
-
functionName: 'execute'
|
|
135
|
-
});
|
|
136
|
-
},
|
|
137
|
-
encodeCalls: async (calls) => encodeCalls(calls),
|
|
138
|
-
entryPoint: {
|
|
139
|
-
abi: entryPoint08Abi,
|
|
140
|
-
address: entryPoint08Address,
|
|
141
|
-
version: '0.8'
|
|
142
|
-
},
|
|
143
|
-
estimate: async (parameters) => {
|
|
144
|
-
const opData = encodePacked(['uint192', 'bytes'], [0n, STUB_SIGNATURE]);
|
|
145
|
-
|
|
146
|
-
const data = encodeFunctionData({
|
|
147
|
-
abi: simulationAbi,
|
|
148
|
-
args: [EXECUTION_MODE_OP_DATA, encodeCalls(parameters.calls, opData)],
|
|
149
|
-
functionName: 'simulateExecute'
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
const stateOverride: StateOverride = [
|
|
153
|
-
{
|
|
154
|
-
address: owner.address,
|
|
155
|
-
code: simulationBytecode
|
|
156
|
-
}
|
|
157
|
-
];
|
|
158
|
-
|
|
159
|
-
const [estimatedGas, estimatedL1Fee, deployed] = await Promise.all([
|
|
160
|
-
estimateGas(client, {
|
|
161
|
-
blockTag: 'pending',
|
|
162
|
-
data,
|
|
163
|
-
stateOverride,
|
|
164
|
-
to: owner.address
|
|
165
|
-
}),
|
|
166
|
-
estimateL1Fee(client, owner.address, data),
|
|
167
|
-
isDeployed()
|
|
168
|
-
]);
|
|
169
|
-
|
|
170
|
-
return {
|
|
171
|
-
estimatedGas: estimatedGas + delegationGas(deployed ? 0 : 1),
|
|
172
|
-
estimatedL1Fee
|
|
173
|
-
};
|
|
174
|
-
},
|
|
175
|
-
getAddress: async () => owner.address,
|
|
176
|
-
getFactoryArgs: async () => ({
|
|
177
|
-
factory: '0x7702',
|
|
178
|
-
factoryData: '0x'
|
|
179
|
-
}),
|
|
180
|
-
getNonce,
|
|
181
|
-
getStubSignature: async () => STUB_SIGNATURE,
|
|
182
|
-
isDeployed,
|
|
183
|
-
signAuthorization: () =>
|
|
184
|
-
viem_signAuthorization(client, {
|
|
185
|
-
account: owner,
|
|
186
|
-
address: GELATO_DELEGATION_ADDRESS,
|
|
187
|
-
chainId: client.chain.id
|
|
188
|
-
}),
|
|
189
|
-
signMessage: (parameters) =>
|
|
190
|
-
signMessage(client, {
|
|
191
|
-
account: owner,
|
|
192
|
-
message: parameters.message
|
|
193
|
-
}),
|
|
194
|
-
signTypedData: (parameters) =>
|
|
195
|
-
signTypedData(client, {
|
|
196
|
-
...(parameters as TypedDataDefinition),
|
|
197
|
-
account: owner
|
|
198
|
-
}),
|
|
199
|
-
signUserOperation: async (parameters) => {
|
|
200
|
-
const typedData = getUserOperationTypedData({
|
|
201
|
-
chainId: client.chain.id,
|
|
202
|
-
entryPointAddress: entryPoint08Address,
|
|
203
|
-
userOperation: {
|
|
204
|
-
...parameters,
|
|
205
|
-
sender: parameters.sender ?? owner.address
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
return signTypedData(client, {
|
|
210
|
-
...typedData,
|
|
211
|
-
account: owner
|
|
212
|
-
});
|
|
213
|
-
},
|
|
214
|
-
type: 'smart'
|
|
215
|
-
};
|
|
216
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './gelato/index.js';
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { Abi, Call, Chain, Hex, SignedAuthorization } from 'viem';
|
|
2
|
-
import type { EntryPointVersion, SmartAccountImplementation } from 'viem/account-abstraction';
|
|
3
|
-
|
|
4
|
-
export type EstimateParameters = {
|
|
5
|
-
calls: Call[];
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type EstimateReturnType = {
|
|
9
|
-
estimatedGas: bigint;
|
|
10
|
-
estimatedL1Fee?: bigint;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type EncodeCallDataParameters = EstimateParameters & {
|
|
14
|
-
nonce: bigint;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type GelatoSmartAccountExtension = {
|
|
18
|
-
chain: Chain;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type GelatoSmartAccountActions = {
|
|
22
|
-
estimate: (parameters: EstimateParameters) => Promise<EstimateReturnType>;
|
|
23
|
-
encodeCallData: (parameters: EncodeCallDataParameters) => Promise<Hex>;
|
|
24
|
-
signAuthorization: () => Promise<SignedAuthorization>;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type GelatoSmartAccountImplementation<
|
|
28
|
-
entryPointAbi extends Abi | readonly unknown[] = Abi,
|
|
29
|
-
entryPointVersion extends EntryPointVersion = EntryPointVersion
|
|
30
|
-
> = SmartAccountImplementation<
|
|
31
|
-
entryPointAbi,
|
|
32
|
-
entryPointVersion,
|
|
33
|
-
GelatoSmartAccountExtension,
|
|
34
|
-
true
|
|
35
|
-
> &
|
|
36
|
-
GelatoSmartAccountActions;
|
package/account/index.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { Hex } from 'viem';
|
|
2
|
-
import type { SmartAccount } from 'viem/account-abstraction';
|
|
3
|
-
import {
|
|
4
|
-
createGelatoEvmRelayerClient,
|
|
5
|
-
type FeeQuote,
|
|
6
|
-
type GelatoEvmRelayerClient,
|
|
7
|
-
type TerminalStatus
|
|
8
|
-
} from '../relayer/index.js';
|
|
9
|
-
import {
|
|
10
|
-
type GetFeeQuoteParameters,
|
|
11
|
-
getFeeQuote,
|
|
12
|
-
type SendTransactionParameters,
|
|
13
|
-
type SendTransactionSyncParameters,
|
|
14
|
-
sendTransaction,
|
|
15
|
-
sendTransactionSync
|
|
16
|
-
} from './actions/index.js';
|
|
17
|
-
import type { GelatoSmartAccountImplementation } from './adapters/types/index.js';
|
|
18
|
-
|
|
19
|
-
export * from './adapters/index.js';
|
|
20
|
-
|
|
21
|
-
export type GelatoSmartAccountClient = Pick<
|
|
22
|
-
GelatoEvmRelayerClient,
|
|
23
|
-
'getCapabilities' | 'getStatus' | 'waitForStatus'
|
|
24
|
-
> & {
|
|
25
|
-
sendTransaction: (parameters: SendTransactionParameters) => Promise<Hex>;
|
|
26
|
-
sendTransactionSync: (parameters: SendTransactionSyncParameters) => Promise<TerminalStatus>;
|
|
27
|
-
getFeeQuote: (parameters: GetFeeQuoteParameters) => Promise<FeeQuote>;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export type GelatoSmartAccountClientConfig = {
|
|
31
|
-
apiKey: string;
|
|
32
|
-
account: SmartAccount<GelatoSmartAccountImplementation>;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const createGelatoSmartAccountClient = async (
|
|
36
|
-
parameters: GelatoSmartAccountClientConfig
|
|
37
|
-
): Promise<GelatoSmartAccountClient> => {
|
|
38
|
-
const { account, apiKey } = parameters;
|
|
39
|
-
|
|
40
|
-
const client = createGelatoEvmRelayerClient({
|
|
41
|
-
apiKey,
|
|
42
|
-
testnet: account.chain.testnet ?? false
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const capabilities = (await client.getCapabilities())[account.chain.id];
|
|
46
|
-
|
|
47
|
-
if (!capabilities) {
|
|
48
|
-
throw new Error(`Chain not supported: ${account.chain.id}`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
getCapabilities: () => client.getCapabilities(),
|
|
53
|
-
getFeeQuote: (parameters) => getFeeQuote(client, account, capabilities, parameters),
|
|
54
|
-
getStatus: (parameters) => client.getStatus(parameters),
|
|
55
|
-
sendTransaction: (parameters) => sendTransaction(client, account, capabilities, parameters),
|
|
56
|
-
sendTransactionSync: (parameters) =>
|
|
57
|
-
sendTransactionSync(client, account, capabilities, parameters),
|
|
58
|
-
waitForStatus: (parameters) => client.waitForStatus(parameters)
|
|
59
|
-
};
|
|
60
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type Address, concatHex, type Hex } from 'viem';
|
|
2
|
-
|
|
3
|
-
const DELEGATION_GAS = 25_000n;
|
|
4
|
-
|
|
5
|
-
export const delegationGas = (authorizationCount: number): bigint => {
|
|
6
|
-
return DELEGATION_GAS * BigInt(authorizationCount);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const delegationCode = (address: Address): Hex => concatHex(['0xef0100', address]);
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Address,
|
|
3
|
-
type Chain,
|
|
4
|
-
type ChainContract,
|
|
5
|
-
type Client,
|
|
6
|
-
type Hex,
|
|
7
|
-
type Transport,
|
|
8
|
-
zeroAddress
|
|
9
|
-
} from 'viem';
|
|
10
|
-
import { estimateL1Fee as viem_estimateL1Fee } from 'viem/op-stack';
|
|
11
|
-
|
|
12
|
-
export const estimateL1Fee = async (
|
|
13
|
-
client: Client<Transport, Chain>,
|
|
14
|
-
to: Address,
|
|
15
|
-
data: Hex
|
|
16
|
-
): Promise<bigint | undefined> => {
|
|
17
|
-
const gasPriceOracle = client.chain.contracts?.['gasPriceOracle'] as ChainContract | undefined;
|
|
18
|
-
|
|
19
|
-
if (!gasPriceOracle) {
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return await viem_estimateL1Fee(client, {
|
|
24
|
-
account: zeroAddress,
|
|
25
|
-
data,
|
|
26
|
-
gasPriceOracleAddress: gasPriceOracle.address,
|
|
27
|
-
to
|
|
28
|
-
});
|
|
29
|
-
};
|
package/account/utils/index.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { BaseError, Chain, Client, Transport } from 'viem';
|
|
2
|
-
import {
|
|
3
|
-
type EstimateUserOperationGasParameters,
|
|
4
|
-
type EstimateUserOperationGasReturnType,
|
|
5
|
-
formatUserOperationGas,
|
|
6
|
-
formatUserOperationRequest,
|
|
7
|
-
getUserOperationError,
|
|
8
|
-
type PrepareUserOperationParameters,
|
|
9
|
-
type SmartAccount,
|
|
10
|
-
type UserOperation
|
|
11
|
-
} from 'viem/account-abstraction';
|
|
12
|
-
import { parseAccount } from 'viem/accounts';
|
|
13
|
-
import type { CapabilitiesByChain } from '../../relayer/evm/actions/index.js';
|
|
14
|
-
import { AccountNotFoundError, type Payment } from '../../types/index.js';
|
|
15
|
-
import { serializeStateOverride } from '../../utils/index.js';
|
|
16
|
-
import { prepareUserOperation } from './prepareUserOperation.js';
|
|
17
|
-
|
|
18
|
-
export const estimateUserOperationGas = async <account extends SmartAccount | undefined>(
|
|
19
|
-
client: Client<Transport, Chain | undefined, account>,
|
|
20
|
-
parameters: EstimateUserOperationGasParameters,
|
|
21
|
-
capabilities: CapabilitiesByChain,
|
|
22
|
-
payment?: Payment
|
|
23
|
-
): Promise<EstimateUserOperationGasReturnType> => {
|
|
24
|
-
const { account: account_ = client.account, entryPointAddress, stateOverride } = parameters;
|
|
25
|
-
|
|
26
|
-
if (!account_ && !parameters.sender) throw new AccountNotFoundError();
|
|
27
|
-
const account = account_ ? parseAccount(account_) : undefined;
|
|
28
|
-
|
|
29
|
-
const rpcStateOverride = serializeStateOverride(stateOverride);
|
|
30
|
-
|
|
31
|
-
const request = account
|
|
32
|
-
? await prepareUserOperation(
|
|
33
|
-
client,
|
|
34
|
-
{
|
|
35
|
-
...parameters,
|
|
36
|
-
parameters: ['authorization', 'factory', 'nonce', 'paymaster', 'signature']
|
|
37
|
-
} as unknown as PrepareUserOperationParameters,
|
|
38
|
-
capabilities,
|
|
39
|
-
payment
|
|
40
|
-
)
|
|
41
|
-
: parameters;
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
const params = [
|
|
45
|
-
formatUserOperationRequest(request as UserOperation),
|
|
46
|
-
// biome-ignore lint/style/noNonNullAssertion: copied from viem
|
|
47
|
-
(entryPointAddress ?? account?.entryPoint?.address)!
|
|
48
|
-
] as const;
|
|
49
|
-
|
|
50
|
-
const result = await client.request({
|
|
51
|
-
method: 'eth_estimateUserOperationGas',
|
|
52
|
-
params: rpcStateOverride ? [...params, rpcStateOverride] : [...params]
|
|
53
|
-
});
|
|
54
|
-
return formatUserOperationGas(result) as EstimateUserOperationGasReturnType<account>;
|
|
55
|
-
} catch (error) {
|
|
56
|
-
// biome-ignore lint/suspicious/noExplicitAny: copied from viem
|
|
57
|
-
const calls = (parameters as any).calls;
|
|
58
|
-
throw getUserOperationError(error as BaseError, {
|
|
59
|
-
...(request as UserOperation),
|
|
60
|
-
...(calls ? { calls } : {})
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
};
|