|
| 1 | +import { |
| 2 | + MatchingEngine, |
| 3 | + TokenRouter, |
| 4 | +} from "@wormhole-foundation/example-liquidity-layer-definitions"; |
| 5 | +import { Chain, Network, encoding, toChainId } from "@wormhole-foundation/sdk-base"; |
| 6 | +import { |
| 7 | + AccountAddress, |
| 8 | + CircleBridge, |
| 9 | + Contracts, |
| 10 | + UnsignedTransaction, |
| 11 | + VAA, |
| 12 | + serialize, |
| 13 | +} from "@wormhole-foundation/sdk-definitions"; |
| 14 | +import { |
| 15 | + AnyEvmAddress, |
| 16 | + EvmAddress, |
| 17 | + EvmChains, |
| 18 | + EvmUnsignedTransaction, |
| 19 | +} from "@wormhole-foundation/sdk-evm"; |
| 20 | +import { ethers } from "ethers"; |
| 21 | +import { MatchingEngine as _MatchingEngine } from "../MatchingEngine"; |
| 22 | + |
| 23 | +export class EvmMatchingEngine<N extends Network, C extends EvmChains> |
| 24 | + extends _MatchingEngine |
| 25 | + implements MatchingEngine<N, C> |
| 26 | +{ |
| 27 | + constructor( |
| 28 | + readonly network: N, |
| 29 | + readonly chain: C, |
| 30 | + provider: ethers.Provider, |
| 31 | + readonly contracts: Contracts & MatchingEngine.Addresses, |
| 32 | + ) { |
| 33 | + super(provider, contracts.matchingEngine, contracts.cctp.tokenMessenger); |
| 34 | + } |
| 35 | + registerRouter<RC extends Chain>( |
| 36 | + sender: AccountAddress<C>, |
| 37 | + chain: RC, |
| 38 | + cctpDomain: number, |
| 39 | + router: AccountAddress<RC>, |
| 40 | + tokenAccount?: AccountAddress<C> | undefined, |
| 41 | + ): AsyncGenerator<UnsignedTransaction<N, C>, any, unknown> { |
| 42 | + throw new Error("Method not implemented."); |
| 43 | + } |
| 44 | + updateRouter<RC extends Chain>( |
| 45 | + sender: AccountAddress<C>, |
| 46 | + chain: RC, |
| 47 | + cctpDomain: number, |
| 48 | + router: AccountAddress<RC>, |
| 49 | + tokenAccount?: AccountAddress<C> | undefined, |
| 50 | + ): AsyncGenerator<UnsignedTransaction<N, C>, any, unknown> { |
| 51 | + throw new Error("Method not implemented."); |
| 52 | + } |
| 53 | + disableRouter<RC extends Chain>( |
| 54 | + sender: AccountAddress<C>, |
| 55 | + chain: RC, |
| 56 | + ): AsyncGenerator<UnsignedTransaction<N, C>, any, unknown> { |
| 57 | + throw new Error("Method not implemented."); |
| 58 | + } |
| 59 | + setPause( |
| 60 | + sender: AccountAddress<C>, |
| 61 | + pause: boolean, |
| 62 | + ): AsyncGenerator<UnsignedTransaction<N, C>, any, unknown> { |
| 63 | + throw new Error("Method not implemented."); |
| 64 | + } |
| 65 | + setConfiguration(config: { |
| 66 | + enabled: boolean; |
| 67 | + maxAmount: bigint; |
| 68 | + baseFee: bigint; |
| 69 | + initAuctionFee: bigint; |
| 70 | + }): AsyncGenerator<UnsignedTransaction<N, C>, any, unknown> { |
| 71 | + throw new Error("Method not implemented."); |
| 72 | + } |
| 73 | + placeInitialOffer( |
| 74 | + sender: AccountAddress<C>, |
| 75 | + vaa: VAA<"FastTransfer:FastMarketOrder">, |
| 76 | + offerPrice: bigint, |
| 77 | + totalDeposit?: bigint | undefined, |
| 78 | + ): AsyncGenerator<UnsignedTransaction<N, C>, any, unknown> { |
| 79 | + throw new Error("Method not implemented."); |
| 80 | + } |
| 81 | + improveOffer( |
| 82 | + sender: AccountAddress<C>, |
| 83 | + vaa: VAA<"FastTransfer:FastMarketOrder">, |
| 84 | + offer: bigint, |
| 85 | + ): AsyncGenerator<UnsignedTransaction<N, C>, any, unknown> { |
| 86 | + throw new Error("Method not implemented."); |
| 87 | + } |
| 88 | + executeFastOrder( |
| 89 | + sender: AccountAddress<C>, |
| 90 | + vaa: VAA<"FastTransfer:FastMarketOrder">, |
| 91 | + ): AsyncGenerator<UnsignedTransaction<N, C>, any, unknown> { |
| 92 | + throw new Error("Method not implemented."); |
| 93 | + } |
| 94 | + prepareOrderResponse( |
| 95 | + sender: AccountAddress<C>, |
| 96 | + vaa: VAA<"FastTransfer:FastMarketOrder">, |
| 97 | + deposit: VAA<"FastTransfer:CctpDeposit">, |
| 98 | + cctp: CircleBridge.Attestation, |
| 99 | + ): AsyncGenerator<UnsignedTransaction<N, C>, any, unknown> { |
| 100 | + throw new Error("Method not implemented."); |
| 101 | + } |
| 102 | + settleOrder( |
| 103 | + sender: AccountAddress<C>, |
| 104 | + fast: VAA<"FastTransfer:FastMarketOrder">, |
| 105 | + deposit?: VAA<"FastTransfer:CctpDeposit"> | undefined, |
| 106 | + cctp?: CircleBridge.Attestation | undefined, |
| 107 | + ): AsyncGenerator<UnsignedTransaction<N, C>, any, unknown> { |
| 108 | + throw new Error("Method not implemented."); |
| 109 | + } |
| 110 | + |
| 111 | + //async *redeemFill( |
| 112 | + // sender: AnyEvmAddress, |
| 113 | + // vaa: VAA<"FastTransfer:CctpDeposit"> | VAA<"FastTransfer:FastFill">, |
| 114 | + // cctp?: CircleBridge.Attestation, |
| 115 | + //) { |
| 116 | + // const from = new EvmAddress(sender).unwrap(); |
| 117 | + // const txReq = await this.redeemFillTx({ |
| 118 | + // encodedWormholeMessage: serialize(vaa), |
| 119 | + // circleBridgeMessage: cctp ? CircleBridge.serialize(cctp.message) : new Uint8Array(), |
| 120 | + // circleAttestation: cctp ? encoding.hex.decode(cctp.attestation!) : new Uint8Array(), |
| 121 | + // }); |
| 122 | + // yield this.createUnsignedTx({ ...txReq, from }, "TokenRouter.redeemFill"); |
| 123 | + //} |
| 124 | + |
| 125 | + private createUnsignedTx( |
| 126 | + txReq: ethers.TransactionRequest, |
| 127 | + description: string, |
| 128 | + parallelizable: boolean = false, |
| 129 | + ): UnsignedTransaction<N, C> { |
| 130 | + return new EvmUnsignedTransaction( |
| 131 | + txReq, |
| 132 | + this.network, |
| 133 | + this.chain, |
| 134 | + description, |
| 135 | + parallelizable, |
| 136 | + ); |
| 137 | + } |
| 138 | +} |
0 commit comments