Skip to content

Commit c81abf7

Browse files
committed
cleanup
1 parent f5e5146 commit c81abf7

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

platforms/aptos/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@
9999
}
100100
}
101101
}
102-
}
102+
}

platforms/evm/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,4 @@
130130
}
131131
}
132132
}
133-
}
133+
}

platforms/evm/protocols/tbtc/src/bridge.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export class EvmTBTCBridge<N extends Network, C extends EvmChains = EvmChains>
3434
gatewayAddress: string;
3535
gateway: Contract;
3636

37+
tbtcTokenAddr: string;
38+
3739
constructor(
3840
readonly network: N,
3941
readonly chain: C,
@@ -48,6 +50,11 @@ export class EvmTBTCBridge<N extends Network, C extends EvmChains = EvmChains>
4850
throw new Error('TBTC contract address is required');
4951
}
5052

53+
const tbtcToken = TBTCBridge.getNativeTbtcToken(this.chain);
54+
if (!tbtcToken) {
55+
throw new Error('Native tbtc token not found');
56+
}
57+
5158
this.chainId = nativeChainIds.networkChainToNativeChainId.get(
5259
network,
5360
chain,
@@ -65,6 +72,8 @@ export class EvmTBTCBridge<N extends Network, C extends EvmChains = EvmChains>
6572
],
6673
provider,
6774
);
75+
76+
this.tbtcTokenAddr = canonicalAddress(tbtcToken);
6877
}
6978

7079
static async fromRpc<N extends Network>(
@@ -87,11 +96,6 @@ export class EvmTBTCBridge<N extends Network, C extends EvmChains = EvmChains>
8796
): AsyncGenerator<EvmUnsignedTransaction<N, C>> {
8897
const senderAddress = new EvmAddress(sender).toString();
8998

90-
const tbtcToken = TBTCBridge.getNativeTbtcToken(this.chain);
91-
if (!tbtcToken) {
92-
throw new Error('Native tbtc token not found');
93-
}
94-
9599
const tx = await this.gateway.sendTbtc!.populateTransaction(
96100
amount,
97101
toChainId(recipient.chain),
@@ -101,12 +105,7 @@ export class EvmTBTCBridge<N extends Network, C extends EvmChains = EvmChains>
101105
);
102106
tx.value = await this.core.getMessageFee();
103107

104-
yield* this.approve(
105-
canonicalAddress(tbtcToken),
106-
senderAddress,
107-
amount,
108-
this.gatewayAddress,
109-
);
108+
yield* this.approve(senderAddress, amount, this.gatewayAddress);
110109

111110
yield this.createUnsignedTransaction(
112111
addFrom(tx, senderAddress),
@@ -118,6 +117,10 @@ export class EvmTBTCBridge<N extends Network, C extends EvmChains = EvmChains>
118117
sender: AccountAddress<C>,
119118
vaa: TBTCBridge.VAA,
120119
): AsyncGenerator<EvmUnsignedTransaction<N, C>> {
120+
if (vaa.payloadName !== 'GatewayTransfer') {
121+
throw new Error('Invalid VAA payload');
122+
}
123+
121124
const address = new EvmAddress(sender).toString();
122125

123126
const tx = await this.gateway.receiveTbtc!.populateTransaction(
@@ -131,14 +134,13 @@ export class EvmTBTCBridge<N extends Network, C extends EvmChains = EvmChains>
131134
}
132135

133136
private async *approve(
134-
token: string,
135137
senderAddr: string,
136138
amount: bigint,
137139
contract: string,
138140
): AsyncGenerator<EvmUnsignedTransaction<N, C>> {
139141
const tokenContract = EvmPlatform.getTokenImplementation(
140142
this.provider,
141-
token,
143+
this.tbtcTokenAddr,
142144
);
143145
const allowance = await tokenContract.allowance(senderAddr, contract);
144146
if (allowance < amount) {

platforms/solana/protocols/tbtc/src/bridge.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ export class SolanaTBTCBridge<N extends Network, C extends SolanaChains>
135135

136136
const coreFeeCollector = coreUtils.deriveFeeCollectorKey(this.coreBridgeId);
137137

138+
// NOTE: There is a race condition where the sequence changes
139+
// while the transaction is in flight. This would cause the
140+
// transaction to fail and the user would have to retry.
138141
const { sequence } = await coreUtils.getProgramSequenceTracker(
139142
this.connection,
140143
this.tokenBridgeId,
141144
this.coreBridgeId,
142145
);
143146

144-
// NOTE: There is a race condition where the sequence changes
145-
// before the transaction is confirmed. This would cause the
146-
// transaction to fail.
147147
const coreMessage = getCoreMessagePda(this.gateway.programId, sequence);
148148

149149
const coreBridgeData = coreUtils.deriveWormholeBridgeDataKey(

sdk/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,4 +413,4 @@
413413
"@wormhole-foundation/sdk-algorand-tokenbridge": "1.0.3"
414414
},
415415
"type": "module"
416-
}
416+
}

0 commit comments

Comments
 (0)