//////////////////////////////////////// import { Static, TLiteral, Type } from "@sinclair/typebox"; import { ChannelRpcMethod, ChannelRpcMethods } from "../vectorProvider"; import { TBasicMeta, TAddress, TBytes32, TPublicIdentifier, TChainId, TIntegerString, TransferResolverSchema, WithdrawalQuoteSchema, TransferQuoteSchema, } from "./basic"; //////////////////////////////////////// // Engine API Parameter schemas // The engine takes in user-friendly channel transition parameters // from the rpc, converts them to proper protocol/message parameters, // and returns the protocol/message response. const GetWithdrawalQuoteParamsSchema = Type.Object({ amount: TIntegerString, assetId: TAddress, channelAddress: TAddress, receiveExactAmount: Type.Optional(Type.Boolean()), }); const GetTransferQuoteParamsSchema = Type.Object({ routerIdentifier: TPublicIdentifier, amount: TIntegerString, assetId: TAddress, chainId: TChainId, recipient: Type.Optional(TPublicIdentifier), recipientChainId: Type.Optional(TChainId), recipientAssetId: Type.Optional(TAddress), receiveExactAmount: Type.Optional(Type.Boolean()), }); const GetRouterConfigParamsSchema = Type.Object({ routerIdentifier: TPublicIdentifier, }); // Get transfer state by resolver id params const GetTransferStateByRoutingIdParamsSchema = Type.Object({ channelAddress: TAddress, routingId: TBytes32, }); const GetTransferStatesByRoutingIdParamsSchema = Type.Object({ routingId: TBytes32, }); // Get channel state params const GetChannelStateParamsSchema = Type.Object({ channelAddress: TAddress }); // Get channel states params const GetChannelStatesParamsSchema = Type.Object({}); // Get channel state by participants params const GetChannelStateByParticipantsParamsSchema = Type.Object({ alice: TPublicIdentifier, bob: TPublicIdentifier, chainId: TChainId, }); // Returns all active transfers for the channel const GetActiveTransfersParamsSchema = Type.Object({ channelAddress: TAddress, }); // Returns the transfer associated with the transferID const GetTransferStateParamsSchema = Type.Object({ transferId: TBytes32, }); // Returns transfers optionally filtered export const GetTransfersFilterOptsSchema = Type.Object({ channelAddress: Type.Optional(TAddress), startDate: Type.Optional(Type.Any()), // no date type endDate: Type.Optional(Type.Any()), // no date type active: Type.Optional(Type.Boolean()), routingId: Type.Optional(TBytes32), transferDefinition: Type.Optional(TAddress), }); export type GetTransfersFilterOpts = Static; const GetTransfersParamsSchema = Type.Object({ filterOpts: Type.Optional(GetTransfersFilterOptsSchema), }); // Returns all registered transfer info const GetRegisteredTransfersParamsSchema = Type.Object({ chainId: TChainId, }); // Returns withdrawal commitment by transfer id const GetWithdrawalCommitmentParamsSchema = Type.Object({ transferId: TBytes32, }); // Returns withdrawal commitment by transaction hash const GetWithdrawalCommitmentByTransactionHashParamsSchema = Type.Object({ transactionHash: TBytes32, }); // Setup engine params const SetupEngineParamsSchema = Type.Object({ counterpartyIdentifier: TPublicIdentifier, chainId: TChainId, timeout: Type.Optional(TIntegerString), meta: Type.Optional(TBasicMeta), }); // Deposit engine params const DepositEngineParamsSchema = Type.Object({ channelAddress: TAddress, assetId: TAddress, meta: Type.Optional(TBasicMeta), }); // Request collateral engine params const RequestCollateralEngineParamsSchema = Type.Object({ channelAddress: TAddress, assetId: TAddress, amount: Type.Optional(TIntegerString), }); // Create conditional transfer engine params const CreateConditionalTransferParamsSchema = Type.Object({ channelAddress: TAddress, amount: TIntegerString, assetId: TAddress, recipient: Type.Optional(TPublicIdentifier), recipientChainId: Type.Optional(TChainId), recipientAssetId: Type.Optional(TAddress), timeout: Type.Optional(TIntegerString), meta: Type.Optional(TBasicMeta), type: Type.String(), details: Type.Dict(Type.Any()), // initial state w.o balance object quote: Type.Optional(TransferQuoteSchema), }); // Resolve conditional transfer engine params const ResolveTransferParamsSchema = Type.Object({ channelAddress: TAddress, transferId: TBytes32, meta: Type.Optional(TBasicMeta), transferResolver: TransferResolverSchema, }); // Withdraw engine params const WithdrawParamsSchema = Type.Object({ channelAddress: TAddress, amount: TIntegerString, assetId: TAddress, recipient: TAddress, timeout: Type.Optional(TIntegerString), quote: Type.Optional(WithdrawalQuoteSchema), callTo: Type.Optional(TAddress), callData: Type.Optional(Type.String()), meta: Type.Optional(TBasicMeta), initiatorSubmits: Type.Optional(Type.Boolean()), }); // Withdraw Retry engine const WithdrawRetryParamsSchema = Type.Object({ channelAddress: TAddress, transferId: TBytes32, }); // Add transaction to commitment params const AddTransactionToCommitmentParamsSchema = Type.Object({ transactionHash: TBytes32, channelAddress: TAddress, transferId: TBytes32, }); ////////////////// /// Dispute Methods // Dispute channel engine params const DisputeChannelParamsSchema = Type.Object({ channelAddress: TAddress, }); // Defund channel engine params const DefundChannelParamsSchema = Type.Object({ channelAddress: TAddress, }); // Get channel dispute engine params const GetChannelDisputeParamsSchema = Type.Object({ channelAddress: TAddress, }); // Dispute transfer engine params const DisputeTransferParamsSchema = Type.Object({ transferId: TBytes32, }); // Defund transfer engine params const DefundTransferParamsSchema = Type.Object({ transferId: TBytes32, }); // Get transfer dispute engine params const GetTransferDisputeParamsSchema = Type.Object({ transferId: TBytes32, }); // Exit funds from channel params const ExitChannelParamsSchema = Type.Object({ channelAddress: TAddress, assetIds: Type.Array(TAddress), recipient: Type.Optional(TAddress), owner: Type.Optional(TAddress), }); // Utility-sign a message const SignUtilityMessageParamsSchema = Type.Object({ message: Type.String(), }); // Ping-pong const SendIsAliveParamsSchema = Type.Object({ channelAddress: TAddress, skipCheckIn: Type.Boolean() }); // Restore channel from counterparty const RestoreStateParamsSchema = Type.Object({ counterpartyIdentifier: TPublicIdentifier, chainId: TChainId, }); // Rpc request schema const RpcRequestEngineParamsSchema = Type.Object({ id: Type.Number({ minimum: 1 }), jsonrpc: Type.Literal("2.0"), method: Type.Union( Object.values(ChannelRpcMethods).map((methodName) => Type.Literal(methodName)) as [TLiteral], ), params: Type.Optional(Type.Any()), // NOTE: Safe to make params an object here, in engine the // params will be validated after the method is dispatched }); // Namespace export // eslint-disable-next-line @typescript-eslint/no-namespace export namespace EngineParams { export const RpcRequestSchema = RpcRequestEngineParamsSchema; export type RpcRequest = Static; export const GetRouterConfigSchema = GetRouterConfigParamsSchema; export type GetRouterConfig = Static; export const SignUtilityMessageSchema = SignUtilityMessageParamsSchema; export type SignUtilityMessage = Static; export const SendIsAliveSchema = SendIsAliveParamsSchema; export type SendIsAlive = Static; export const GetTransferStateByRoutingIdSchema = GetTransferStateByRoutingIdParamsSchema; export type GetTransferStateByRoutingId = Static; export const GetTransferStatesByRoutingIdSchema = GetTransferStatesByRoutingIdParamsSchema; export type GetTransferStatesByRoutingId = Static; export const GetChannelStatesSchema = GetChannelStatesParamsSchema; export type GetChannelStates = Static; export const GetChannelStateSchema = GetChannelStateParamsSchema; export type GetChannelState = Static; export const GetChannelStateByParticipantsSchema = GetChannelStateByParticipantsParamsSchema; export type GetChannelStateByParticipants = Static; export const GetActiveTransfersSchema = GetActiveTransfersParamsSchema; export type GetActiveTransfers = Static; export const GetTransferStateSchema = GetTransferStateParamsSchema; export type GetTransferState = Static; export const GetTransfersSchema = GetTransfersParamsSchema; export type GetTransfers = Static; export const GetRegisteredTransfersSchema = GetRegisteredTransfersParamsSchema; export type GetRegisteredTransfers = Static; export const GetWithdrawalCommitmentSchema = GetWithdrawalCommitmentParamsSchema; export type GetWithdrawalCommitment = Static; export const GetWithdrawalCommitmentByTransactionHashSchema = GetWithdrawalCommitmentByTransactionHashParamsSchema; export type GetWithdrawalCommitmentByTransactionHash = Static< typeof GetWithdrawalCommitmentByTransactionHashParamsSchema >; export const SetupSchema = SetupEngineParamsSchema; export type Setup = Static; export const RestoreStateSchema = RestoreStateParamsSchema; export type RestoreState = Static; export const DepositSchema = DepositEngineParamsSchema; export type Deposit = Static; export const RequestCollateralSchema = RequestCollateralEngineParamsSchema; export type RequestCollateral = Static; export const ConditionalTransferSchema = CreateConditionalTransferParamsSchema; export type ConditionalTransfer = Static; export const ResolveTransferSchema = ResolveTransferParamsSchema; export type ResolveTransfer = Static; export const WithdrawSchema = WithdrawParamsSchema; export type Withdraw = Static; export const WithdrawRetrySchema = WithdrawRetryParamsSchema; export type WithdrawRetry = Static; export const AddTransactionToCommitmentSchema = AddTransactionToCommitmentParamsSchema; export type AddTransactionToCommitment = Static; export const DisputeChannelSchema = DisputeChannelParamsSchema; export type DisputeChannel = Static; export const DefundChannelSchema = DefundChannelParamsSchema; export type DefundChannel = Static; export const GetChannelDisputeSchema = GetChannelDisputeParamsSchema; export type GetChannelDispute = Static; export const DisputeTransferSchema = DisputeTransferParamsSchema; export type DisputeTransfer = Static; export const DefundTransferSchema = DefundTransferParamsSchema; export type DefundTransfer = Static; export const GetTransferDisputeSchema = GetTransferDisputeParamsSchema; export type GetTransferDispute = Static; export const ExitChannelSchema = ExitChannelParamsSchema; export type ExitChannel = Static; export const GetTransferQuoteSchema = GetTransferQuoteParamsSchema; export type GetTransferQuote = Static; export const GetWithdrawalQuoteSchema = GetWithdrawalQuoteParamsSchema; export type GetWithdrawalQuote = Static; }