Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/starkweb/src/core/actions/executeTransaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
type ExecuteTransactionErrorType as strkjs_ExecuteTransactionErrorType,
type ExecuteTransactionParameters as strkjs_ExecuteTransactionParameters,
type ExecuteTransactionReturnType as strkjs_ExecuteTransactionReturnType,
executeTransaction as strkjs_executeTransaction,
} from "../../actions/paymaster/executeTransaction.js";
import type { Hex } from "../../types/misc.js";

import type { Config } from "../createConfig.js";
import type { ChainIdParameter } from "../types/properties.js";
import type { Evaluate } from "../types/utils.js";
import { getAction } from "../utils/getAction.js";

export type ExecuteTransactionParameters = Evaluate<
strkjs_ExecuteTransactionParameters & ChainIdParameter
>;

export type ExecuteTransactionReturnType = Evaluate<
strkjs_ExecuteTransactionReturnType & {
chainId: Hex;
}
>;

export type ExecuteTransactionErrorType =
strkjs_ExecuteTransactionErrorType;

export async function executeTransaction(
config: Config,
parameters: ExecuteTransactionParameters
): Promise<ExecuteTransactionReturnType> {
const { chainId, ...rest } = parameters;
const client = config.getClient({ chainId });
const action = getAction(
client,
strkjs_executeTransaction,
"executeTransaction"
);
return action(rest) as Promise<ExecuteTransactionReturnType>;
}
39 changes: 39 additions & 0 deletions packages/starkweb/src/core/actions/getGasTokenPrices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
type GetGasTokenPricesErrorType as strkjs_GetGasTokenPricesErrorType,
type GetGasTokenPricesParameters as strkjs_GetGasTokenPricesParameters,
type GetGasTokenPricesReturnType as strkjs_GetGasTokenPricesReturnType,
getGasTokenPrices as strkjs_getGasTokenPrices,
} from "../../actions/paymaster/getGasTokenPrices.js";
import type { Hex } from "../../types/misc.js";

import type { Config } from "../createConfig.js";
import type { ChainIdParameter } from "../types/properties.js";
import type { Evaluate } from "../types/utils.js";
import { getAction } from "../utils/getAction.js";

export type GetGasTokenPricesParameters = Evaluate<
strkjs_GetGasTokenPricesParameters & ChainIdParameter
>;

export type GetGasTokenPricesReturnType = Evaluate<
strkjs_GetGasTokenPricesReturnType & {
chainId: Hex;
}
>;

export type GetGasTokenPricesErrorType =
strkjs_GetGasTokenPricesErrorType;

export async function getGasTokenPrices(
config: Config,
parameters: GetGasTokenPricesParameters & Record<string, unknown>
): Promise<GetGasTokenPricesReturnType> {
const { chainId } = parameters;
const client = config.getClient({ chainId });
const action = getAction(
client,
strkjs_getGasTokenPrices,
"getGasTokenPrices"
);
return action(chainId) as Promise<GetGasTokenPricesReturnType>;
}
65 changes: 34 additions & 31 deletions packages/starkweb/src/core/actions/getPaymasterStatus.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
import { useState } from 'react';
import { createPaymasterClient } from '../../exports/starkweb.js';
import { http } from '../../exports/starkweb.js';
import { mainnet, sepolia } from '../../exports/chains.js';
import type { GaslessStatus } from '../../types/paymaster.js';
import {
type GetPaymasterStatusErrorType as strkjs_GetPaymasterStatusErrorType,
type GetPaymasterStatusParameters as strkjs_GetPaymasterStatusParameters,
type GetPaymasterStatusReturnType as strkjs_GetPaymasterStatusReturnType,
getPaymasterStatus as strkjs_getPaymasterStatus,
} from "../../actions/paymaster/getPaymasterStatus.js";
import type { Hex } from "../../types/misc.js";

/**
* Fetches the current status of the Paymaster.
*
* @param {('mainnet' | 'sepolia')} network - The network to connect to, either 'mainnet' or 'sepolia'.
* @param {string} [url='http://localhost:3003/paymaster'] - Optional URL for the Paymaster service. Defaults to 'http://localhost:3003/paymaster.
* @returns {Object} An object containing the status, loading state, and error message.
*/
export const fetchPaymasterStatus = async (network: 'mainnet' | 'sepolia', url: string = 'http://localhost:3003/paymaster') => {
const [status, setStatus] = useState<GaslessStatus | null>(null);
const [loading, setLoading] = useState<boolean>(false);
const [error, setError] = useState<string | null>(null);
import type { Config } from "../createConfig.js";
import type { ChainIdParameter } from "../types/properties.js";
import type { Evaluate } from "../types/utils.js";
import { getAction } from "../utils/getAction.js";

const chain = network === 'mainnet' ? mainnet : sepolia;
const paymasterClient = createPaymasterClient({
chain,
transport: http(`${url}/paymaster/${network}`),
});
export type GetPaymasterStatusParameters = Evaluate<
strkjs_GetPaymasterStatusParameters & ChainIdParameter
>;

setLoading(true);
try {
const paymasterStatus = await paymasterClient.getPaymasterStatus();
setStatus(paymasterStatus);
} catch (err) {
setError('Failed to fetch paymaster status');
} finally {
setLoading(false);
export type GetPaymasterStatusReturnType = Evaluate<
strkjs_GetPaymasterStatusReturnType & {
chainId: Hex;
}
>;

return { status, loading, error };
};
export type GetPaymasterStatusErrorType =
strkjs_GetPaymasterStatusErrorType;

export async function getPaymasterStatus(
config: Config,
parameters: GetPaymasterStatusParameters
): Promise<GetPaymasterStatusReturnType> {
const { chainId } = parameters;
const client = config.getClient({ chainId });
const action = getAction(
client,
strkjs_getPaymasterStatus,
"getPaymasterStatus"
);
return action(undefined) as Promise<GetPaymasterStatusReturnType>;
}
48 changes: 46 additions & 2 deletions packages/starkweb/src/core/exports/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export {
getWalletClientQueryOptions,
} from "../query/getWalletClient.js";


// Starknet ID Queries

export {
Expand Down Expand Up @@ -309,4 +308,49 @@ export {
verifyTypedDataQueryOptions,
} from "../query/verifyTypedData.js";

export { hashFn, structuralSharing } from '../query/utils.js'
export { hashFn, structuralSharing } from "../query/utils.js";




// PAYMASTER QUERIES //

export {
type GetPaymasterStatusQueryKey,
type GetPaymasterStatusReturnType,
type GetPaymasterStatusErrorType,
getPaymasterStatusQueryKey,
getPaymasterStatusQueryOptions,
} from "../query/getPaymasterStatus.js";

export {
type CheckAccountCompatibilityQueryKey,
type CheckAccountCompatibilityReturnType,
type CheckAccountCompatibilityErrorType,
checkAccountCompatibilityQueryKey,
checkAccountCompatibilityQueryOptions,
} from "../query/checkAccountCompatibility.js";

export {
type GetAccountRewardsQueryKey,
type GetAccountRewardsReturnType,
type GetAccountRewardsErrorType,
getAccountRewardsQueryKey,
getAccountRewardsQueryOptions,
} from "../query/getAccountRewards.js";

export {
type GetGasTokenPricesQueryKey,
type GetGasTokenPricesReturnType,
type GetGasTokenPricesErrorType,
getGasTokenPricesQueryKey,
getGasTokenPricesQueryOptions,
} from "../query/getGasTokenPrices.js";

export {
type ExecuteTransactionQueryKey,
type ExecuteTransactionReturnType,
type ExecuteTransactionErrorType,
executeTransactionQueryKey,
executeTransactionQueryOptions,
} from "../query/executeTransaction.js";
10 changes: 9 additions & 1 deletion packages/starkweb/src/core/query/buildTypedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
import type { QueryOptions } from '@tanstack/query-core'

import {
type BuildTypedDataErrorType,
type BuildTypedDataErrorType as strkjs_BuildTypedDataErrorType,
type BuildTypedDataParameters,
type BuildTypedDataReturnType,
buildTypedData,
} from "../actions/buildTypedData.js";
import type { Config } from "../createConfig.js";
import { filterQueryOptions } from "./utils.js";
import type { Evaluate, ExactPartial } from '../types/utils.js';


export type BuildTypedDataOptions = Evaluate<
ExactPartial<BuildTypedDataParameters>
>;

export function buildTypedDataQueryOptions(
config: Config,
Expand All @@ -25,3 +31,5 @@ export function buildTypedDataQueryKey(parameters: BuildTypedDataParameters) {
}

export type BuildTypedDataQueryKey = ReturnType<typeof buildTypedDataQueryKey>
export type BuildTypedDataData = BuildTypedDataReturnType
export type BuildTypedDataErrorType = strkjs_BuildTypedDataErrorType
32 changes: 32 additions & 0 deletions packages/starkweb/src/core/query/checkAccountCompatibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { QueryOptions } from '@tanstack/query-core';
import {
type CheckAccountCompatibilityErrorType as strkjs_CheckAccountCompatibilityErrorType,
type CheckAccountCompatibilityParameters,
type CheckAccountCompatibilityReturnType,
checkAccountCompatibility,
} from "../actions/checkAccountCompatibility.js";
import type { Config } from "../createConfig.js";
import type { Evaluate, ExactPartial } from '../types/utils.js';


export type CheckAccountCompatibilityOptions = Evaluate<
ExactPartial<CheckAccountCompatibilityParameters>
>;

export function checkAccountCompatibilityQueryOptions(
config: Config,
parameters: CheckAccountCompatibilityParameters
): QueryOptions<CheckAccountCompatibilityReturnType, CheckAccountCompatibilityErrorType> {
return {
queryKey: checkAccountCompatibilityQueryKey(parameters),
queryFn: () => checkAccountCompatibility(config, parameters),
};
}

export function checkAccountCompatibilityQueryKey(parameters: CheckAccountCompatibilityParameters) {
return ['checkAccountCompatibility', parameters] as const;
}

export type CheckAccountCompatibilityQueryKey = ReturnType<typeof checkAccountCompatibilityQueryKey>;
export type checkAccountCompatibilityData = CheckAccountCompatibilityReturnType;
export type CheckAccountCompatibilityErrorType = strkjs_CheckAccountCompatibilityErrorType
37 changes: 37 additions & 0 deletions packages/starkweb/src/core/query/executeTransaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { QueryOptions } from '@tanstack/query-core';
import {
type ExecuteTransactionErrorType as strkjs_ExecuteTransactionErrorType,
type ExecuteTransactionParameters,
type ExecuteTransactionReturnType,
executeTransaction,
} from "../actions/executeTransaction.js";
import type { Evaluate, ExactPartial } from '../types/utils.js';
import type { ScopeKeyParameter } from '../types/properties.js'

import type { Config } from "../createConfig.js";

export type ExecuteTransactionOptions = Evaluate<
ExactPartial<ExecuteTransactionParameters> & ScopeKeyParameter
>;
// Placeholder for executeTransactionQueryKey function
function executeTransactionQueryKey(parameters: ExecuteTransactionParameters) {
return ['executeTransaction', parameters] as const;
}

export function executeTransactionQueryOptions(
config: Config,
parameters: ExecuteTransactionParameters
): QueryOptions<ExecuteTransactionReturnType, ExecuteTransactionErrorType> {
return {
queryKey: executeTransactionQueryKey(parameters),
queryFn: () => executeTransaction(config, parameters),
};
}

export function GetExecuteTransactionData(parameters: ExecuteTransactionParameters) {
return ['executeTransaction', parameters] as const;
}

export type ExecuteTransactionQueryKey = ReturnType<typeof executeTransactionQueryKey>;
export type ExecuteTransactionData = ExecuteTransactionReturnType;
export type ExecuteTransactionErrorType = strkjs_ExecuteTransactionErrorType;
34 changes: 34 additions & 0 deletions packages/starkweb/src/core/query/getAccountRewards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { QueryOptions } from '@tanstack/query-core';
import {
type GetAccountRewardsErrorType as strkjs_GetAccountRewardsErrorType,
type GetAccountRewardsParameters,
type GetAccountRewardsReturnType,
getAccountRewards,

} from "../actions/getAccountRewards.js";
import type { Config } from "../createConfig.js";
import type { Evaluate, ExactPartial } from '../types/utils.js';
import type { ScopeKeyParameter } from '../types/properties.js'


export type GetAccountRewardsOptions = Evaluate<
ExactPartial<GetAccountRewardsParameters> & ScopeKeyParameter
>;

export function getAccountRewardsQueryOptions(
config: Config,
parameters: GetAccountRewardsParameters
): QueryOptions<GetAccountRewardsReturnType, GetAccountRewardsErrorType> {
return {
queryKey: getAccountRewardsQueryKey(parameters),
queryFn: () => getAccountRewards(config, parameters),
};
}

export function getAccountRewardsQueryKey(parameters: GetAccountRewardsParameters) {
return ['getAccountRewards', parameters] as const;
}

export type GetAccountRewardsQueryKey = ReturnType<typeof getAccountRewardsQueryKey>;
export type GetAccountRewardsErrorType = strkjs_GetAccountRewardsErrorType
export type GetAccountRewardsData = GetAccountRewardsReturnType;
32 changes: 32 additions & 0 deletions packages/starkweb/src/core/query/getGasTokenPrices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { QueryOptions } from '@tanstack/query-core';
import {
type GetGasTokenPricesErrorType as strkjs_GetGasTokenPricesErrorType,
type GetGasTokenPricesParameters,
type GetGasTokenPricesReturnType,
getGasTokenPrices,
} from "../actions/getGasTokenPrices.js";
import type { Config } from "../createConfig.js";
import type { Evaluate, ExactPartial } from '../types/utils.js';
import type { ScopeKeyParameter } from '../types/properties.js'


export type GetGasTokenPricesOptions = Evaluate<
ExactPartial<GetGasTokenPricesParameters> & ScopeKeyParameter
>;
export function getGasTokenPricesQueryOptions(
config: Config,
parameters: GetGasTokenPricesParameters
): QueryOptions<GetGasTokenPricesReturnType, GetGasTokenPricesErrorType> {
return {
queryKey: getGasTokenPricesQueryKey(parameters),
queryFn: () => getGasTokenPrices(config, parameters),
};
}

export function getGasTokenPricesQueryKey(parameters: GetGasTokenPricesParameters) {
return ['getGasTokenPrices', parameters] as const;
}

export type GetGasTokenPricesQueryKey = ReturnType<typeof getGasTokenPricesQueryKey>;
export type GetGasTokenPricesData = GetGasTokenPricesReturnType;
export type GetGasTokenPricesErrorType = strkjs_GetGasTokenPricesErrorType
Loading