|
| 1 | +import "@typespec/http"; |
| 2 | +import "@typespec/openapi"; |
| 3 | + |
| 4 | +using Http; |
| 5 | +using OpenAPI; |
| 6 | + |
| 7 | +@service() |
| 8 | +@info(#{ |
| 9 | + title: "Messaging Executor API", |
| 10 | + version: "1.0.0", |
| 11 | +}) |
| 12 | +@server("http://localhost:3000/v0", "Local development server") |
| 13 | +namespace MessagingExecutor; |
| 14 | + |
| 15 | +// ============= Models ============= |
| 16 | + |
| 17 | +model Capabilities { |
| 18 | + @doc("Request prefixes enabled for given chain") |
| 19 | + requestPrefixes: string[]; |
| 20 | + |
| 21 | + @doc("Gas Drop-off limit, native chain token bigint represented as string") |
| 22 | + gasDropOffLimit?: string; |
| 23 | + |
| 24 | + @doc("Maximum Gas limit") |
| 25 | + maxGasLimit?: string; |
| 26 | + |
| 27 | + @doc("Max message value, native chain token bigint represented as string") |
| 28 | + maxMsgValue?: string; |
| 29 | +} |
| 30 | + |
| 31 | +@doc("Object with chain IDs (Wormhole Chain ID) as keys and their capabilities as values") |
| 32 | +model CapabilitiesResponse is Record<Capabilities>; |
| 33 | + |
| 34 | +model QuoteRequest { |
| 35 | + @doc("Source wormhole chain ID") |
| 36 | + srcChain: int32; |
| 37 | + |
| 38 | + @doc("Destination wormhole chain ID") |
| 39 | + dstChain: int32; |
| 40 | + |
| 41 | + @doc("Optional hex-encoded relay instructions for cost estimation") |
| 42 | + relayInstructions?: string; |
| 43 | +} |
| 44 | + |
| 45 | +model QuoteResponse { |
| 46 | + @doc("Hex-encoded signed quote") |
| 47 | + signedQuote: string; |
| 48 | + |
| 49 | + @doc("Estimated cost in source chain native token units") |
| 50 | + estimatedCost?: string; |
| 51 | +} |
| 52 | + |
| 53 | +model StatusRequest { |
| 54 | + @doc("Wormhole chain ID for the transaction") |
| 55 | + chainId?: int32; |
| 56 | + |
| 57 | + @doc("Transaction hash") |
| 58 | + txHash: string; |
| 59 | +} |
| 60 | + |
| 61 | +model TxInfo { |
| 62 | + @doc("Relayed transaction hash") |
| 63 | + txHash: string; |
| 64 | + |
| 65 | + @doc("Wormhole chain ID for the transaction") |
| 66 | + chainId: int32; |
| 67 | + |
| 68 | + @doc("Block number (or slot/epoch)") |
| 69 | + blockNumber: string; |
| 70 | + |
| 71 | + @doc("Block time as timestamp") |
| 72 | + blockTime?: string; |
| 73 | + |
| 74 | + @doc("Relay cost in native token units (wei/lamports/etc)") |
| 75 | + cost: string; |
| 76 | +} |
| 77 | + |
| 78 | +model RequestForExecution { |
| 79 | + @doc("Public key of Quoter") |
| 80 | + quoterAddress: string; |
| 81 | + |
| 82 | + @doc("Amount paid for the relay in source chain native token") |
| 83 | + amtPaid: string; |
| 84 | + |
| 85 | + @doc("Destination Wormhole chain ID") |
| 86 | + dstChain: int32; |
| 87 | + |
| 88 | + @doc("Destination address to execute the transaction") |
| 89 | + dstAddr: string; |
| 90 | + |
| 91 | + @doc("Refund address for excess payment") |
| 92 | + refundAddr: string; |
| 93 | + |
| 94 | + @doc("Hex-encoded signed quote bytes") |
| 95 | + signedQuoteBytes: string; |
| 96 | + |
| 97 | + @doc("Hex-encoded request bytes") |
| 98 | + requestBytes: string; |
| 99 | + |
| 100 | + @doc("Hex-encoded relay instruction bytes") |
| 101 | + relayInstructionsBytes: string; |
| 102 | + |
| 103 | + @doc("Timestamp when the request was created") |
| 104 | + timestamp: string; |
| 105 | +} |
| 106 | + |
| 107 | +model SignedQuote { |
| 108 | + @doc("Quote details") |
| 109 | + quote: { |
| 110 | + @doc("Quote prefix identifier (e.g., 'EQ01')") |
| 111 | + prefix: string; |
| 112 | + |
| 113 | + @doc("Address of the quoter providing the quote") |
| 114 | + quoterAddress: string; |
| 115 | + |
| 116 | + @doc("Address that will receive payment") |
| 117 | + payeeAddress: string; |
| 118 | + |
| 119 | + @doc("Source Wormhole chain ID") |
| 120 | + srcChain: int32; |
| 121 | + |
| 122 | + @doc("Destination Wormhole chain ID") |
| 123 | + dstChain: int32; |
| 124 | + |
| 125 | + @doc("Quote expiration time") |
| 126 | + expiryTime: string; |
| 127 | + |
| 128 | + @doc("Base fee for the relay") |
| 129 | + baseFee: string; |
| 130 | + |
| 131 | + @doc("Gas price on destination chain") |
| 132 | + dstGasPrice: string; |
| 133 | + |
| 134 | + @doc("Source chain token price") |
| 135 | + srcPrice: string; |
| 136 | + |
| 137 | + @doc("Destination chain token price") |
| 138 | + dstPrice: string; |
| 139 | + }; |
| 140 | + |
| 141 | + @doc("Cryptographic signature of the quote") |
| 142 | + signature?: string; |
| 143 | +} |
| 144 | + |
| 145 | +// Request instruction variants based on prefix |
| 146 | +model ERV1Request { |
| 147 | + @doc("Request prefix identifier") |
| 148 | + prefix: "ERV1"; |
| 149 | + |
| 150 | + @doc("Chain ID") |
| 151 | + chain: int32; |
| 152 | + |
| 153 | + @doc("Contract address") |
| 154 | + address: string; |
| 155 | + |
| 156 | + @doc("Sequence number") |
| 157 | + sequence: string; |
| 158 | +} |
| 159 | + |
| 160 | +model ERN1Request { |
| 161 | + @doc("Request prefix identifier") |
| 162 | + prefix: "ERN1"; |
| 163 | + |
| 164 | + @doc("Source chain ID") |
| 165 | + srcChain: int32; |
| 166 | + |
| 167 | + @doc("Source manager address") |
| 168 | + srcManager: string; |
| 169 | + |
| 170 | + @doc("Message identifier") |
| 171 | + messageId: string; |
| 172 | +} |
| 173 | + |
| 174 | +model ERC1Request { |
| 175 | + @doc("Request prefix identifier") |
| 176 | + prefix: "ERC1"; |
| 177 | + |
| 178 | + @doc("Source domain") |
| 179 | + sourceDomain: int32; |
| 180 | + |
| 181 | + @doc("Nonce value") |
| 182 | + nonce: string; |
| 183 | +} |
| 184 | + |
| 185 | +model ERC2Request { |
| 186 | + @doc("Request prefix identifier") |
| 187 | + prefix: "ERC2"; |
| 188 | + |
| 189 | + @doc("CCTP V2 request configuration") |
| 190 | + cctpV2Request: { |
| 191 | + @doc("CCTP V2 request prefix mode") |
| 192 | + cctpV2RequestPrefix: string; |
| 193 | + }; |
| 194 | +} |
| 195 | + |
| 196 | +@doc("Request instruction details that vary by prefix type") |
| 197 | +model RequestInstruction { |
| 198 | + @doc("The request details, structure depends on the prefix type") |
| 199 | + request: ERV1Request | ERN1Request | ERC1Request | ERC2Request; |
| 200 | +} |
| 201 | + |
| 202 | +model RelayTransaction { |
| 203 | + @doc("Wormhole chain ID where the transaction originated") |
| 204 | + chainId: int32; |
| 205 | + |
| 206 | + @doc("Estimated cost for the relay in source chain native token") |
| 207 | + estimatedCost: string; |
| 208 | + |
| 209 | + @doc("Unique identifier for the relay transaction") |
| 210 | + id: string; |
| 211 | + |
| 212 | + @doc("Timestamp when the transaction was indexed") |
| 213 | + indexedAt: string; |
| 214 | + |
| 215 | + @doc("Parsed relay instruction details") |
| 216 | + instruction?: RequestInstruction; |
| 217 | + |
| 218 | + @doc("Original request for execution details") |
| 219 | + requestForExecution: RequestForExecution; |
| 220 | + |
| 221 | + @doc("Signed quote used for this transaction") |
| 222 | + signedQuote: SignedQuote; |
| 223 | + |
| 224 | + @doc("Current status of the relay (pending, submitted, failed, etc.)") |
| 225 | + status: string; |
| 226 | + |
| 227 | + @doc("Original transaction hash") |
| 228 | + txHash: string; |
| 229 | + |
| 230 | + @doc("Reason for failure if status is 'failed'") |
| 231 | + failureCause?: string; |
| 232 | + |
| 233 | + @doc("List of destination chain transactions executed") |
| 234 | + txs?: TxInfo[]; |
| 235 | +} |
| 236 | + |
| 237 | +@error |
| 238 | +model ErrorResponse { |
| 239 | + message: string; |
| 240 | + statusCode?: int32; |
| 241 | +} |
| 242 | + |
| 243 | +// ============= Interfaces ============= |
| 244 | + |
| 245 | +@route("/capabilities") |
| 246 | +@tag("Capabilities") |
| 247 | +interface CapabilitiesInterface { |
| 248 | + @summary("Get capabilities for all supported chains") |
| 249 | + @doc("Retrieves the supported features and capabilities for all supported blockchains (as wormhole chain ID)") |
| 250 | + @get |
| 251 | + list(): CapabilitiesResponse | ErrorResponse; |
| 252 | +} |
| 253 | + |
| 254 | +@route("/quote") |
| 255 | +@tag("Quote") |
| 256 | +interface QuoteInterface { |
| 257 | + @summary("Generate a quote for cross-chain transaction") |
| 258 | + @doc("Provides a signed quote for cross-chain relay with optional cost estimation") |
| 259 | + @post |
| 260 | + create(@body body: QuoteRequest): QuoteResponse | ErrorResponse; |
| 261 | +} |
| 262 | + |
| 263 | +@route("/status") |
| 264 | +@tag("Status") |
| 265 | +interface StatusInterface { |
| 266 | + @summary("Get status of a transaction") |
| 267 | + @doc("Retrieves the status of a request for execution transaction and potentially initiates processing (when first time statusing and chain ID provided)") |
| 268 | + @route("tx") |
| 269 | + @post |
| 270 | + getTransaction(@body body: StatusRequest): RelayTransaction[] | ErrorResponse; |
| 271 | +} |
0 commit comments