mirror of
https://github.com/0xbow-io/privacy-pools-core.git
synced 2026-01-09 01:17:58 -05:00
feat: added WithdrawalData encoding util
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import {
|
||||
Address,
|
||||
Chain,
|
||||
ContractFunctionExecutionError,
|
||||
ContractFunctionRevertedError,
|
||||
decodeAbiParameters, DecodeAbiParametersErrorType,
|
||||
encodeAbiParameters,
|
||||
EncodeAbiParametersErrorType,
|
||||
BaseError as ViemError
|
||||
} from "viem";
|
||||
import {
|
||||
@@ -15,7 +18,13 @@ import {
|
||||
} from "./interfaces/relayer/request.js";
|
||||
import { FeeDataAbi } from "./types/abi.types.js";
|
||||
|
||||
export function decodeWithdrawalData(data: `0x${string}`) {
|
||||
interface WithdrawalData {
|
||||
recipient: Address,
|
||||
feeRecipient: Address,
|
||||
relayFeeBPS: bigint
|
||||
}
|
||||
|
||||
export function decodeWithdrawalData(data: `0x${string}`): WithdrawalData {
|
||||
try {
|
||||
const [{ recipient, feeRecipient, relayFeeBPS }] = decodeAbiParameters(
|
||||
FeeDataAbi,
|
||||
@@ -31,6 +40,18 @@ export function decodeWithdrawalData(data: `0x${string}`) {
|
||||
}
|
||||
}
|
||||
|
||||
export function encodeWithdrawalData(withdrawalData: WithdrawalData): `0x${string}` {
|
||||
try {
|
||||
return encodeAbiParameters(FeeDataAbi, [withdrawalData])
|
||||
} catch (e) {
|
||||
const error = e as EncodeAbiParametersErrorType;
|
||||
throw WithdrawalValidationError.invalidWithdrawalAbi({
|
||||
name: error.name,
|
||||
message: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function parseSignals(
|
||||
signals: RelayRequestBody["publicSignals"],
|
||||
): WithdrawPublicSignals {
|
||||
@@ -61,9 +82,9 @@ export function parseSignals(
|
||||
* @param {object} chainConfig - The chain configuration
|
||||
* @returns {Chain} - The Chain object
|
||||
*/
|
||||
export function createChainObject(chainConfig: {
|
||||
chain_id: number;
|
||||
chain_name: string;
|
||||
export function createChainObject(chainConfig: {
|
||||
chain_id: number;
|
||||
chain_name: string;
|
||||
rpc_url: string;
|
||||
native_currency?: { name: string; symbol: string; decimals: number };
|
||||
}): Chain {
|
||||
|
||||
Reference in New Issue
Block a user