|
9 | 9 | ChainAddress,
|
10 | 10 | ChainsConfig,
|
11 | 11 | Contracts,
|
12 |
| - TokenAddress, |
13 |
| - VAA, |
14 | 12 | serialize,
|
15 | 13 | universalAddress,
|
16 | 14 | } from "@wormhole-foundation/sdk-definitions";
|
@@ -100,7 +98,7 @@ export class EvmNtt<N extends Network, C extends EvmChains>
|
100 | 98 | readonly chain: C,
|
101 | 99 | readonly provider: Provider,
|
102 | 100 | readonly contracts: Contracts & { ntt?: Ntt.Contracts },
|
103 |
| - readonly version: string = "default" |
| 101 | + readonly version: string = "1.0.0" |
104 | 102 | ) {
|
105 | 103 | if (!contracts.ntt) throw new Error("No Ntt Contracts provided");
|
106 | 104 |
|
@@ -143,19 +141,41 @@ export class EvmNtt<N extends Network, C extends EvmChains>
|
143 | 141 | return enabled.filter((x) => x).length > 0;
|
144 | 142 | }
|
145 | 143 |
|
146 |
| - getIsExecuted(attestation: Ntt.Attestation): Promise<boolean> { |
147 |
| - const { emitterChain: chain, payload } = |
148 |
| - attestation as VAA<"Ntt:WormholeTransfer">; |
149 |
| - return this.manager.isMessageExecuted( |
150 |
| - Ntt.messageDigest(chain, payload["nttManagerPayload"]) |
| 144 | + async getIsExecuted(attestation: Ntt.Attestation): Promise<boolean> { |
| 145 | + const payload = |
| 146 | + attestation.payloadName === "WormholeTransfer" |
| 147 | + ? attestation.payload |
| 148 | + : attestation.payload.payload; |
| 149 | + const isExecuted = await this.manager.isMessageExecuted( |
| 150 | + Ntt.messageDigest(attestation.emitterChain, payload["nttManagerPayload"]) |
| 151 | + ); |
| 152 | + if (!isExecuted) return false; |
| 153 | + // Also check that the transfer is not queued for it to be considered complete |
| 154 | + return !(await this.getIsTransferInboundQueued(attestation)); |
| 155 | + } |
| 156 | + |
| 157 | + async getIsTransferInboundQueued( |
| 158 | + attestation: Ntt.Attestation |
| 159 | + ): Promise<boolean> { |
| 160 | + const payload = |
| 161 | + attestation.payloadName === "WormholeTransfer" |
| 162 | + ? attestation.payload |
| 163 | + : attestation.payload.payload; |
| 164 | + return ( |
| 165 | + (await this.getInboundQueuedTransfer( |
| 166 | + attestation.emitterChain, |
| 167 | + payload["nttManagerPayload"] |
| 168 | + )) !== null |
151 | 169 | );
|
152 | 170 | }
|
153 | 171 |
|
154 | 172 | getIsApproved(attestation: Ntt.Attestation): Promise<boolean> {
|
155 |
| - const { emitterChain: chain, payload } = |
156 |
| - attestation as VAA<"Ntt:WormholeTransfer">; |
| 173 | + const payload = |
| 174 | + attestation.payloadName === "WormholeTransfer" |
| 175 | + ? attestation.payload |
| 176 | + : attestation.payload.payload; |
157 | 177 | return this.manager.isMessageApproved(
|
158 |
| - Ntt.messageDigest(chain, payload["nttManagerPayload"]) |
| 178 | + Ntt.messageDigest(attestation.emitterChain, payload["nttManagerPayload"]) |
159 | 179 | );
|
160 | 180 | }
|
161 | 181 |
|
@@ -311,7 +331,13 @@ export class EvmNtt<N extends Network, C extends EvmChains>
|
311 | 331 |
|
312 | 332 | for (const idx in this.xcvrs) {
|
313 | 333 | const xcvr = this.xcvrs[idx]!;
|
314 |
| - yield* xcvr.receive(attestations[idx]); |
| 334 | + const attestation = attestations[idx]; |
| 335 | + if (attestation?.payloadName !== "WormholeTransfer") { |
| 336 | + // TODO: support standard relayer attestations |
| 337 | + // which must be submitted to the delivery provider |
| 338 | + throw new Error("Invalid attestation type for redeem"); |
| 339 | + } |
| 340 | + yield* xcvr.receive(attestation); |
315 | 341 | }
|
316 | 342 | }
|
317 | 343 |
|
@@ -349,12 +375,12 @@ export class EvmNtt<N extends Network, C extends EvmChains>
|
349 | 375 | async *completeInboundQueuedTransfer(
|
350 | 376 | fromChain: Chain,
|
351 | 377 | transceiverMessage: Ntt.Message,
|
352 |
| - token: TokenAddress<C>, |
353 | 378 | payer?: AccountAddress<C>
|
354 | 379 | ) {
|
355 |
| - const tx = await this.manager.completeInboundQueuedTransfer( |
356 |
| - Ntt.messageDigest(fromChain, transceiverMessage) |
357 |
| - ); |
| 380 | + const tx = |
| 381 | + await this.manager.completeInboundQueuedTransfer.populateTransaction( |
| 382 | + Ntt.messageDigest(fromChain, transceiverMessage) |
| 383 | + ); |
358 | 384 | yield this.createUnsignedTx(tx, "Ntt.completeInboundQueuedTransfer");
|
359 | 385 | }
|
360 | 386 |
|
|
0 commit comments