@gelatocloud/gasless 0.0.0 → 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/bundler/index.js +1 -1
- package/_dist/bundler/index.js.map +1 -1
- package/_dist/constants/index.d.ts.map +1 -0
- package/_dist/constants/index.js.map +1 -0
- package/_dist/relayer/evm/actions/getGelatoStatus.d.ts +97 -0
- package/_dist/relayer/evm/actions/getGelatoStatus.d.ts.map +1 -0
- package/_dist/relayer/evm/actions/getGelatoStatus.js +78 -0
- package/_dist/relayer/evm/actions/getGelatoStatus.js.map +1 -0
- 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 +3 -0
- package/_dist/relayer/evm/actions/index.d.ts.map +1 -1
- package/_dist/relayer/evm/actions/index.js +3 -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/waitForGelatoStatus.d.ts +4 -0
- package/_dist/relayer/evm/actions/waitForGelatoStatus.d.ts.map +1 -0
- package/_dist/relayer/evm/actions/waitForGelatoStatus.js +19 -0
- package/_dist/relayer/evm/actions/waitForGelatoStatus.js.map +1 -0
- 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 +5 -2
- package/_dist/relayer/evm/index.d.ts.map +1 -1
- package/_dist/relayer/evm/index.js +4 -1
- package/_dist/relayer/evm/index.js.map +1 -1
- package/_dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +17 -9
- package/_dist/relayer/constants/index.d.ts.map +0 -1
- package/_dist/relayer/constants/index.js.map +0 -1
- 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/index.ts +0 -4
- package/relayer/constants/index.ts +0 -2
- 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/getStatus.ts +0 -92
- package/relayer/evm/actions/index.ts +0 -7
- package/relayer/evm/actions/sendTransaction.ts +0 -33
- package/relayer/evm/actions/sendTransactionSync.ts +0 -30
- package/relayer/evm/actions/waitForStatus.ts +0 -24
- package/relayer/evm/index.ts +0 -68
- 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/_dist/{relayer/constants → constants}/index.d.ts +0 -0
- /package/_dist/{relayer/constants → constants}/index.js +0 -0
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { BaseError, Chain, Client, Transport } from 'viem';
|
|
2
|
-
import {
|
|
3
|
-
formatUserOperationRequest,
|
|
4
|
-
getUserOperationError,
|
|
5
|
-
type PrepareUserOperationParameters,
|
|
6
|
-
type SendUserOperationParameters,
|
|
7
|
-
type SendUserOperationReturnType,
|
|
8
|
-
type SmartAccount,
|
|
9
|
-
type UserOperation
|
|
10
|
-
} from 'viem/account-abstraction';
|
|
11
|
-
import { parseAccount } from 'viem/accounts';
|
|
12
|
-
import type { CapabilitiesByChain } from '../../relayer/evm/actions/index.js';
|
|
13
|
-
import { AccountNotFoundError, type Payment } from '../../types/index.js';
|
|
14
|
-
import { prepareUserOperation } from './prepareUserOperation.js';
|
|
15
|
-
|
|
16
|
-
export const sendUserOperation = async <account extends SmartAccount | undefined>(
|
|
17
|
-
client: Client<Transport, Chain | undefined, account>,
|
|
18
|
-
parameters: SendUserOperationParameters,
|
|
19
|
-
capabilities: CapabilitiesByChain,
|
|
20
|
-
payment?: Payment
|
|
21
|
-
): Promise<SendUserOperationReturnType> => {
|
|
22
|
-
const { account: account_ = client.account, entryPointAddress } = parameters;
|
|
23
|
-
|
|
24
|
-
if (!account_ && !parameters.sender) throw new AccountNotFoundError();
|
|
25
|
-
const account = account_ ? parseAccount(account_) : undefined;
|
|
26
|
-
|
|
27
|
-
const request = account
|
|
28
|
-
? await prepareUserOperation(
|
|
29
|
-
client,
|
|
30
|
-
parameters as unknown as PrepareUserOperationParameters,
|
|
31
|
-
capabilities,
|
|
32
|
-
payment,
|
|
33
|
-
true
|
|
34
|
-
)
|
|
35
|
-
: parameters;
|
|
36
|
-
|
|
37
|
-
// biome-ignore lint/style/noNonNullAssertion: copied from viem
|
|
38
|
-
const signature = (parameters.signature ||
|
|
39
|
-
(await account?.signUserOperation?.(request as UserOperation)))!;
|
|
40
|
-
|
|
41
|
-
const rpcParameters = formatUserOperationRequest({
|
|
42
|
-
...request,
|
|
43
|
-
signature
|
|
44
|
-
} as UserOperation);
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
return await client.request(
|
|
48
|
-
{
|
|
49
|
-
method: 'eth_sendUserOperation',
|
|
50
|
-
// biome-ignore lint/style/noNonNullAssertion: copied from viem
|
|
51
|
-
params: [rpcParameters, (entryPointAddress ?? account?.entryPoint?.address)!]
|
|
52
|
-
},
|
|
53
|
-
{ retryCount: 0 }
|
|
54
|
-
);
|
|
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
|
-
signature
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { BaseError, Chain, Client, Transport } from 'viem';
|
|
2
|
-
import {
|
|
3
|
-
formatUserOperationReceipt,
|
|
4
|
-
formatUserOperationRequest,
|
|
5
|
-
getUserOperationError,
|
|
6
|
-
type PrepareUserOperationParameters,
|
|
7
|
-
type SendUserOperationParameters,
|
|
8
|
-
type SmartAccount,
|
|
9
|
-
type UserOperation,
|
|
10
|
-
type UserOperationReceipt
|
|
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 { prepareUserOperation } from './prepareUserOperation.js';
|
|
16
|
-
|
|
17
|
-
export type SendUserOperationSyncParameters = SendUserOperationParameters & {
|
|
18
|
-
timeout: number;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const sendUserOperationSync = async <account extends SmartAccount | undefined>(
|
|
22
|
-
client: Client<Transport, Chain | undefined, account>,
|
|
23
|
-
parameters: SendUserOperationSyncParameters,
|
|
24
|
-
capabilities: CapabilitiesByChain,
|
|
25
|
-
payment?: Payment
|
|
26
|
-
): Promise<UserOperationReceipt> => {
|
|
27
|
-
const { account: account_ = client.account, entryPointAddress, timeout } = parameters;
|
|
28
|
-
|
|
29
|
-
if (!account_ && !parameters.sender) throw new AccountNotFoundError();
|
|
30
|
-
const account = account_ ? parseAccount(account_) : undefined;
|
|
31
|
-
|
|
32
|
-
const request = account
|
|
33
|
-
? await prepareUserOperation(
|
|
34
|
-
client,
|
|
35
|
-
parameters as unknown as PrepareUserOperationParameters,
|
|
36
|
-
capabilities,
|
|
37
|
-
payment,
|
|
38
|
-
true
|
|
39
|
-
)
|
|
40
|
-
: parameters;
|
|
41
|
-
|
|
42
|
-
// biome-ignore lint/style/noNonNullAssertion: copied from viem
|
|
43
|
-
const signature = (parameters.signature ||
|
|
44
|
-
(await account?.signUserOperation?.(request as UserOperation)))!;
|
|
45
|
-
|
|
46
|
-
const rpcParameters = formatUserOperationRequest({
|
|
47
|
-
...request,
|
|
48
|
-
signature
|
|
49
|
-
} as UserOperation);
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
const receipt = await client.request(
|
|
53
|
-
{
|
|
54
|
-
method: 'eth_sendUserOperationSync',
|
|
55
|
-
// biome-ignore lint/style/noNonNullAssertion: copied from viem
|
|
56
|
-
params: [rpcParameters, (entryPointAddress ?? account?.entryPoint?.address)!, { timeout }]
|
|
57
|
-
} as never,
|
|
58
|
-
{ retryCount: 0 }
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
return formatUserOperationReceipt(receipt);
|
|
62
|
-
} catch (error) {
|
|
63
|
-
// biome-ignore lint/suspicious/noExplicitAny: copied from viem
|
|
64
|
-
const calls = (parameters as any).calls;
|
|
65
|
-
throw getUserOperationError(error as BaseError, {
|
|
66
|
-
...(request as UserOperation),
|
|
67
|
-
...(calls ? { calls } : {}),
|
|
68
|
-
signature
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
};
|
package/bundler/index.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { type Chain, type Client, http, type Transport } from 'viem';
|
|
2
|
-
import {
|
|
3
|
-
type BundlerActions,
|
|
4
|
-
type BundlerClient,
|
|
5
|
-
type BundlerClientConfig,
|
|
6
|
-
createBundlerClient,
|
|
7
|
-
type UserOperationReceipt
|
|
8
|
-
} from 'viem/account-abstraction';
|
|
9
|
-
import { GELATO_PROD_API, GELATO_STAGING_API } from '../relayer/constants/index.js';
|
|
10
|
-
import { getCapabilities } from '../relayer/evm/actions/index.js';
|
|
11
|
-
import { type Payment, PaymentType } from '../types/index.js';
|
|
12
|
-
import {
|
|
13
|
-
estimateUserOperationGas,
|
|
14
|
-
type GetUserOperationGasPriceReturnType,
|
|
15
|
-
type GetUserOperationQuoteParameters,
|
|
16
|
-
type GetUserOperationQuoteReturnType,
|
|
17
|
-
getUserOperationGasPrice,
|
|
18
|
-
getUserOperationQuote,
|
|
19
|
-
prepareUserOperation,
|
|
20
|
-
type SendUserOperationSyncParameters,
|
|
21
|
-
sendUserOperation,
|
|
22
|
-
sendUserOperationSync
|
|
23
|
-
} from './actions/index.js';
|
|
24
|
-
|
|
25
|
-
export * from './actions/index.js';
|
|
26
|
-
|
|
27
|
-
export type GelatoBundlerActions = Partial<BundlerActions> & {
|
|
28
|
-
sendUserOperationSync: (
|
|
29
|
-
parameters: SendUserOperationSyncParameters
|
|
30
|
-
) => Promise<UserOperationReceipt>;
|
|
31
|
-
getUserOperationGasPrice: () => Promise<GetUserOperationGasPriceReturnType>;
|
|
32
|
-
getUserOperationQuote: (
|
|
33
|
-
parameters: GetUserOperationQuoteParameters
|
|
34
|
-
) => Promise<GetUserOperationQuoteReturnType>;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export type GelatoBundlerClient = BundlerClient & GelatoBundlerActions;
|
|
38
|
-
|
|
39
|
-
export type GelatoBundlerClientConfig = Omit<BundlerClientConfig, 'transport' | 'userOperation'> & {
|
|
40
|
-
client: Client<Transport, Chain>;
|
|
41
|
-
payment?: Payment;
|
|
42
|
-
apiKey: string;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const createGelatoBundlerClient = async (
|
|
46
|
-
parameters: GelatoBundlerClientConfig
|
|
47
|
-
): Promise<GelatoBundlerClient> => {
|
|
48
|
-
const { client: client_, payment, apiKey } = parameters;
|
|
49
|
-
|
|
50
|
-
// TODO: can just use prod endpoint in the future
|
|
51
|
-
const base = client_.chain.testnet ? GELATO_STAGING_API : GELATO_PROD_API;
|
|
52
|
-
|
|
53
|
-
let endpoint = `${base}/rpc/${client_.chain.id}`;
|
|
54
|
-
|
|
55
|
-
if (payment) {
|
|
56
|
-
endpoint += `?payment=${payment.type}`;
|
|
57
|
-
|
|
58
|
-
if (payment.type === PaymentType.Token) {
|
|
59
|
-
endpoint += `&address=${payment.address}`;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const transport = http(endpoint, {
|
|
64
|
-
fetchOptions: {
|
|
65
|
-
headers: {
|
|
66
|
-
'X-API-Key': apiKey
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const client = createBundlerClient({
|
|
72
|
-
...parameters,
|
|
73
|
-
transport
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
const capabilities = (await getCapabilities(transport({})))[client_.chain.id];
|
|
77
|
-
|
|
78
|
-
if (!capabilities) {
|
|
79
|
-
throw new Error(`Chain not supported: ${client_.chain.id}`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return client.extend(
|
|
83
|
-
(client) =>
|
|
84
|
-
({
|
|
85
|
-
estimateUserOperationGas: (parameters) =>
|
|
86
|
-
estimateUserOperationGas(client, parameters, capabilities, payment),
|
|
87
|
-
getUserOperationGasPrice: () => getUserOperationGasPrice(client, payment),
|
|
88
|
-
getUserOperationQuote: (parameters) =>
|
|
89
|
-
getUserOperationQuote(client, parameters, capabilities, payment),
|
|
90
|
-
prepareUserOperation: (parameters) =>
|
|
91
|
-
prepareUserOperation(client, parameters, capabilities, payment),
|
|
92
|
-
sendUserOperation: (parameters) =>
|
|
93
|
-
sendUserOperation(client, parameters, capabilities, payment),
|
|
94
|
-
sendUserOperationSync: (parameters) =>
|
|
95
|
-
sendUserOperationSync(client, parameters, capabilities, payment)
|
|
96
|
-
}) as GelatoBundlerActions
|
|
97
|
-
) as unknown as GelatoBundlerClient;
|
|
98
|
-
};
|
package/index.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Transport } from 'viem';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { evmAddressSchema, evmTokenSchema } from '../../../types/index.js';
|
|
4
|
-
|
|
5
|
-
const capabilitiesByChainSchema = z.object({
|
|
6
|
-
feeCollector: evmAddressSchema,
|
|
7
|
-
tokens: z.array(evmTokenSchema)
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const capabilitiesSchema = z.record(z.string().pipe(z.coerce.number()), capabilitiesByChainSchema);
|
|
11
|
-
|
|
12
|
-
export type CapabilitiesByChain = z.infer<typeof capabilitiesByChainSchema>;
|
|
13
|
-
export type Capabilities = z.infer<typeof capabilitiesSchema>;
|
|
14
|
-
|
|
15
|
-
export const getCapabilities = async (client: ReturnType<Transport>): Promise<Capabilities> => {
|
|
16
|
-
const result = await client.request({
|
|
17
|
-
method: 'relayer_getCapabilities',
|
|
18
|
-
params: []
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
return capabilitiesSchema.parse(result);
|
|
22
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { Address, Transport } from 'viem';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { evmTokenSchema } from '../../../types/index.js';
|
|
4
|
-
|
|
5
|
-
const feeDataSchema = z.object({
|
|
6
|
-
chainId: z.coerce.number(),
|
|
7
|
-
context: z.unknown().optional(),
|
|
8
|
-
expiry: z.number(),
|
|
9
|
-
gasPrice: z.coerce.bigint(),
|
|
10
|
-
rate: z.number(),
|
|
11
|
-
token: evmTokenSchema
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export type FeeData = z.infer<typeof feeDataSchema>;
|
|
15
|
-
|
|
16
|
-
export type GetFeeDataParameters = {
|
|
17
|
-
chainId: number;
|
|
18
|
-
token: Address;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const getFeeData = async (
|
|
22
|
-
client: ReturnType<Transport>,
|
|
23
|
-
parameters: GetFeeDataParameters
|
|
24
|
-
): Promise<FeeData> => {
|
|
25
|
-
const { chainId, token } = parameters;
|
|
26
|
-
|
|
27
|
-
const result = await client.request({
|
|
28
|
-
method: 'relayer_getFeeData',
|
|
29
|
-
params: {
|
|
30
|
-
chainId: chainId.toString(),
|
|
31
|
-
token
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
return feeDataSchema.parse(result);
|
|
36
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Address, Transport } from 'viem';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { evmTokenSchema } from '../../../types/index.js';
|
|
4
|
-
|
|
5
|
-
const feeQuote = z.object({
|
|
6
|
-
chainId: z.coerce.number(),
|
|
7
|
-
context: z.unknown().optional(),
|
|
8
|
-
expiry: z.number(),
|
|
9
|
-
fee: z.coerce.bigint(),
|
|
10
|
-
token: evmTokenSchema
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
export type FeeQuote = z.infer<typeof feeQuote>;
|
|
14
|
-
|
|
15
|
-
export type GetFeeQuoteParameters = {
|
|
16
|
-
chainId: number;
|
|
17
|
-
gas: bigint;
|
|
18
|
-
l1Fee?: bigint;
|
|
19
|
-
token: Address;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const getFeeQuote = async (
|
|
23
|
-
client: ReturnType<Transport>,
|
|
24
|
-
parameters: GetFeeQuoteParameters
|
|
25
|
-
): Promise<FeeQuote> => {
|
|
26
|
-
const { chainId, gas, l1Fee, token } = parameters;
|
|
27
|
-
|
|
28
|
-
const result = await client.request({
|
|
29
|
-
method: 'relayer_getFeeQuote',
|
|
30
|
-
params: {
|
|
31
|
-
chainId: chainId.toString(),
|
|
32
|
-
gas: gas.toString(),
|
|
33
|
-
l1Fee: l1Fee ? l1Fee.toString() : undefined,
|
|
34
|
-
token
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
return feeQuote.parse(result);
|
|
39
|
-
};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import type { Transport } from 'viem';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { evmAddressSchema, hexData32Schema, hexDataSchema } from '../../../types/index.js';
|
|
4
|
-
|
|
5
|
-
export enum StatusCode {
|
|
6
|
-
Pending = 100,
|
|
7
|
-
Submitted = 110,
|
|
8
|
-
Included = 200,
|
|
9
|
-
Rejected = 400,
|
|
10
|
-
Reverted = 500
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const logSchema = z.object({
|
|
14
|
-
address: evmAddressSchema,
|
|
15
|
-
data: hexDataSchema,
|
|
16
|
-
topics: z.array(hexData32Schema)
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const receiptSchema = z.object({
|
|
20
|
-
blockHash: hexData32Schema,
|
|
21
|
-
blockNumber: z.coerce.bigint(),
|
|
22
|
-
gasUsed: z.coerce.bigint(),
|
|
23
|
-
logs: z.array(logSchema).optional(),
|
|
24
|
-
transactionHash: hexData32Schema
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const baseStatusSchema = z.object({
|
|
28
|
-
chainId: z.coerce.number(),
|
|
29
|
-
createdAt: z.number()
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const pendingStatusSchema = baseStatusSchema.extend({
|
|
33
|
-
status: z.literal(StatusCode.Pending)
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const submittedStatusSchema = baseStatusSchema.extend({
|
|
37
|
-
hash: hexData32Schema,
|
|
38
|
-
status: z.literal(StatusCode.Submitted)
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const includedStatusSchema = baseStatusSchema.extend({
|
|
42
|
-
receipt: receiptSchema,
|
|
43
|
-
status: z.literal(StatusCode.Included)
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const rejectedStatusSchema = baseStatusSchema.extend({
|
|
47
|
-
data: z.unknown().optional(),
|
|
48
|
-
message: z.string(),
|
|
49
|
-
status: z.literal(StatusCode.Rejected)
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const revertedStatusSchema = baseStatusSchema.extend({
|
|
53
|
-
data: z.string(),
|
|
54
|
-
message: z.string().optional(),
|
|
55
|
-
status: z.literal(StatusCode.Reverted)
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
export const terminalStatusSchema = z.discriminatedUnion('status', [
|
|
59
|
-
includedStatusSchema,
|
|
60
|
-
rejectedStatusSchema,
|
|
61
|
-
revertedStatusSchema
|
|
62
|
-
]);
|
|
63
|
-
|
|
64
|
-
export const statusSchema = z.discriminatedUnion('status', [
|
|
65
|
-
pendingStatusSchema,
|
|
66
|
-
submittedStatusSchema,
|
|
67
|
-
includedStatusSchema,
|
|
68
|
-
rejectedStatusSchema,
|
|
69
|
-
revertedStatusSchema
|
|
70
|
-
]);
|
|
71
|
-
|
|
72
|
-
export type TerminalStatus = z.infer<typeof terminalStatusSchema>;
|
|
73
|
-
|
|
74
|
-
export type Status = z.infer<typeof statusSchema>;
|
|
75
|
-
|
|
76
|
-
export type GetStatusParameters = {
|
|
77
|
-
id: string;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export const getStatus = async (
|
|
81
|
-
client: ReturnType<Transport>,
|
|
82
|
-
parameters: GetStatusParameters
|
|
83
|
-
): Promise<Status> => {
|
|
84
|
-
const { id } = parameters;
|
|
85
|
-
|
|
86
|
-
const result = await client.request({
|
|
87
|
-
method: 'relayer_getStatus',
|
|
88
|
-
params: { id }
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
return statusSchema.parse(result);
|
|
92
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { Address, Hex, SignedAuthorizationList, Transport } from 'viem';
|
|
2
|
-
import { hexData32Schema, type Payment } from '../../../types/index.js';
|
|
3
|
-
import { formatAuthorization } from '../../../utils/index.js';
|
|
4
|
-
|
|
5
|
-
export type SendTransactionParameters = {
|
|
6
|
-
authorizationList?: SignedAuthorizationList;
|
|
7
|
-
chainId: number;
|
|
8
|
-
context?: unknown;
|
|
9
|
-
data: Hex;
|
|
10
|
-
payment: Payment;
|
|
11
|
-
to: Address;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const sendTransaction = async (
|
|
15
|
-
client: ReturnType<Transport>,
|
|
16
|
-
parameters: SendTransactionParameters
|
|
17
|
-
): Promise<Hex> => {
|
|
18
|
-
const { chainId, data, to, payment, context, authorizationList } = parameters;
|
|
19
|
-
|
|
20
|
-
const result = await client.request({
|
|
21
|
-
method: 'relayer_sendTransaction',
|
|
22
|
-
params: {
|
|
23
|
-
authorizationList: authorizationList ? authorizationList.map(formatAuthorization) : undefined,
|
|
24
|
-
chainId: chainId.toString(),
|
|
25
|
-
context,
|
|
26
|
-
data,
|
|
27
|
-
payment,
|
|
28
|
-
to
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
return hexData32Schema.parse(result);
|
|
33
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Transport } from 'viem';
|
|
2
|
-
import { formatAuthorization } from '../../../utils/index.js';
|
|
3
|
-
import { type TerminalStatus, terminalStatusSchema } from './getStatus.js';
|
|
4
|
-
import type { SendTransactionParameters } from './sendTransaction.js';
|
|
5
|
-
|
|
6
|
-
export type SendTransactionSyncParameters = SendTransactionParameters & {
|
|
7
|
-
timeout?: number;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const sendTransactionSync = async (
|
|
11
|
-
client: ReturnType<Transport>,
|
|
12
|
-
parameters: SendTransactionSyncParameters
|
|
13
|
-
): Promise<TerminalStatus> => {
|
|
14
|
-
const { chainId, data, to, payment, context, authorizationList, timeout } = parameters;
|
|
15
|
-
|
|
16
|
-
const result = await client.request({
|
|
17
|
-
method: 'relayer_sendTransactionSync',
|
|
18
|
-
params: {
|
|
19
|
-
authorizationList: authorizationList ? authorizationList.map(formatAuthorization) : undefined,
|
|
20
|
-
chainId: chainId.toString(),
|
|
21
|
-
context,
|
|
22
|
-
data,
|
|
23
|
-
payment,
|
|
24
|
-
timeout,
|
|
25
|
-
to
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
return terminalStatusSchema.parse(result);
|
|
30
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Transport } from 'viem';
|
|
2
|
-
import {
|
|
3
|
-
type GetStatusParameters,
|
|
4
|
-
getStatus,
|
|
5
|
-
StatusCode,
|
|
6
|
-
type TerminalStatus
|
|
7
|
-
} from './getStatus.js';
|
|
8
|
-
|
|
9
|
-
// TODO: use websockets
|
|
10
|
-
// TODO: make polling interval configurable
|
|
11
|
-
export const waitForStatus = async (
|
|
12
|
-
client: ReturnType<Transport>,
|
|
13
|
-
parameters: GetStatusParameters
|
|
14
|
-
): Promise<TerminalStatus> => {
|
|
15
|
-
while (true) {
|
|
16
|
-
const status = await getStatus(client, parameters);
|
|
17
|
-
|
|
18
|
-
if (status.status !== StatusCode.Pending && status.status !== StatusCode.Submitted) {
|
|
19
|
-
return status;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
await new Promise((r) => setTimeout(r, 100));
|
|
23
|
-
}
|
|
24
|
-
};
|
package/relayer/evm/index.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { type Hex, type HttpTransportConfig, http } from 'viem';
|
|
2
|
-
import { GELATO_PROD_API, GELATO_STAGING_API } from '../constants/index.js';
|
|
3
|
-
import {
|
|
4
|
-
type Capabilities,
|
|
5
|
-
type FeeData,
|
|
6
|
-
type FeeQuote,
|
|
7
|
-
type GetFeeDataParameters,
|
|
8
|
-
type GetFeeQuoteParameters,
|
|
9
|
-
type GetStatusParameters,
|
|
10
|
-
getCapabilities,
|
|
11
|
-
getFeeData,
|
|
12
|
-
getFeeQuote,
|
|
13
|
-
getStatus,
|
|
14
|
-
type SendTransactionParameters,
|
|
15
|
-
type SendTransactionSyncParameters,
|
|
16
|
-
type Status,
|
|
17
|
-
sendTransaction,
|
|
18
|
-
sendTransactionSync,
|
|
19
|
-
type TerminalStatus,
|
|
20
|
-
waitForStatus
|
|
21
|
-
} from './actions/index.js';
|
|
22
|
-
|
|
23
|
-
export * from './actions/index.js';
|
|
24
|
-
|
|
25
|
-
export type GelatoEvmRelayerClient = {
|
|
26
|
-
getCapabilities: () => Promise<Capabilities>;
|
|
27
|
-
getFeeData: (parameters: GetFeeDataParameters) => Promise<FeeData>;
|
|
28
|
-
getFeeQuote: (parameters: GetFeeQuoteParameters) => Promise<FeeQuote>;
|
|
29
|
-
getStatus: (parameters: GetStatusParameters) => Promise<Status>;
|
|
30
|
-
waitForStatus: (parameters: GetStatusParameters) => Promise<TerminalStatus>;
|
|
31
|
-
sendTransaction: (parameters: SendTransactionParameters) => Promise<Hex>;
|
|
32
|
-
sendTransactionSync: (parameters: SendTransactionSyncParameters) => Promise<TerminalStatus>;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type GelatoEvmRelayerClientConfig = {
|
|
36
|
-
apiKey: string;
|
|
37
|
-
testnet: boolean;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// TODO: the testnet/mainnet separation won't be necessary in the future
|
|
41
|
-
export const createGelatoEvmRelayerClient = (
|
|
42
|
-
parameters: GelatoEvmRelayerClientConfig
|
|
43
|
-
): GelatoEvmRelayerClient => {
|
|
44
|
-
const { apiKey, testnet } = parameters;
|
|
45
|
-
|
|
46
|
-
const config: HttpTransportConfig = {
|
|
47
|
-
fetchOptions: {
|
|
48
|
-
headers: {
|
|
49
|
-
'X-API-Key': apiKey
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// TODO: can just use prod endpoint in the future
|
|
55
|
-
const base = testnet ? GELATO_STAGING_API : GELATO_PROD_API;
|
|
56
|
-
|
|
57
|
-
const client = http(`${base}/rpc`, config)({});
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
getCapabilities: () => getCapabilities(client),
|
|
61
|
-
getFeeData: (parameters) => getFeeData(client, parameters),
|
|
62
|
-
getFeeQuote: (parameters) => getFeeQuote(client, parameters),
|
|
63
|
-
getStatus: (parameters) => getStatus(client, parameters),
|
|
64
|
-
sendTransaction: (parameters) => sendTransaction(client, parameters),
|
|
65
|
-
sendTransactionSync: (parameters) => sendTransactionSync(client, parameters),
|
|
66
|
-
waitForStatus: (parameters) => waitForStatus(client, parameters)
|
|
67
|
-
};
|
|
68
|
-
};
|
package/relayer/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './evm/index.js';
|
package/tsconfig.build.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"declarationMap": true,
|
|
6
|
-
"sourceMap": true,
|
|
7
|
-
"composite": true,
|
|
8
|
-
"noEmit": false,
|
|
9
|
-
"outDir": "./_dist"
|
|
10
|
-
},
|
|
11
|
-
"exclude": [
|
|
12
|
-
"node_modules",
|
|
13
|
-
"_dist",
|
|
14
|
-
"**/*.test.ts",
|
|
15
|
-
"**/*.spec.ts",
|
|
16
|
-
"**/*.test.tsx",
|
|
17
|
-
"**/*.spec.tsx"
|
|
18
|
-
]
|
|
19
|
-
}
|
package/tsconfig.json
DELETED
package/types/error.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// Note: copied from viem since it doesn't export these
|
|
2
|
-
|
|
3
|
-
import { BaseError } from 'viem';
|
|
4
|
-
|
|
5
|
-
export class InvalidBytesLengthError extends BaseError {
|
|
6
|
-
constructor({
|
|
7
|
-
size,
|
|
8
|
-
targetSize,
|
|
9
|
-
type
|
|
10
|
-
}: {
|
|
11
|
-
size: number;
|
|
12
|
-
targetSize: number;
|
|
13
|
-
type: 'hex' | 'bytes';
|
|
14
|
-
}) {
|
|
15
|
-
super(
|
|
16
|
-
`${type.charAt(0).toUpperCase()}${type
|
|
17
|
-
.slice(1)
|
|
18
|
-
.toLowerCase()} is expected to be ${targetSize} ${type} long, but is ${size} ${type} long.`,
|
|
19
|
-
{ name: 'InvalidBytesLengthError' }
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class AccountNotFoundError extends BaseError {
|
|
25
|
-
constructor({ docsPath }: { docsPath?: string | undefined } = {}) {
|
|
26
|
-
super(
|
|
27
|
-
[
|
|
28
|
-
'Could not find an Account to execute with this Action.',
|
|
29
|
-
'Please provide an Account with the `account` argument on the Action, or by supplying an `account` to the Client.'
|
|
30
|
-
].join('\n'),
|
|
31
|
-
{
|
|
32
|
-
docsPath,
|
|
33
|
-
docsSlug: 'account',
|
|
34
|
-
name: 'AccountNotFoundError'
|
|
35
|
-
}
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
}
|
package/types/index.ts
DELETED