Skip to content

Commit

Permalink
pick: contract swaps shouldn't wait for SwapScheduled (#4948)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylezs committed Jun 14, 2024
1 parent 78de605 commit 041942e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
17 changes: 0 additions & 17 deletions bouncer/shared/contract_swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import {
} from '@chainflip/cli';
import { HDNodeWallet, Wallet, getDefaultProvider } from 'ethers';
import {
getChainflipApi,
observeBalanceIncrease,
observeEvent,
getContractAddress,
observeCcmReceived,
amountToFineAmount,
Expand Down Expand Up @@ -85,8 +83,6 @@ export async function performSwapViaContract(
messageMetadata?: CcmDepositMetadata,
swapContext?: SwapContext,
): Promise<ContractSwapParams> {
await using api = await getChainflipApi();

const tag = swapTag ?? '';

const srcChain = chainFromAsset(sourceAsset);
Expand Down Expand Up @@ -136,19 +132,6 @@ export async function performSwapViaContract(
);
swapContext?.updateStatus(swapTag, SwapStatus.ContractExecuted);

await observeEvent('swapping:SwapScheduled', api, (event) => {
if ('Vault' in event.data.origin) {
const sourceAssetMatches = sourceAsset === (event.data.sourceAsset as Asset);
const destAssetMatches = destAsset === (event.data.destinationAsset as Asset);
const txHashMatches = event.data.origin.Vault.txHash === receipt.hash;
return sourceAssetMatches && destAssetMatches && txHashMatches;
}
// Otherwise it was a swap scheduled by requesting a deposit address
return false;
});

swapContext?.updateStatus(swapTag, SwapStatus.SwapScheduled);

console.log(`${tag} Successfully observed event: swapping: SwapScheduled`);

const ccmEventEmitted = messageMetadata
Expand Down
3 changes: 2 additions & 1 deletion bouncer/shared/swapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ export class SwapContext {
}
case SwapStatus.Success: {
assert(
currentStatus === SwapStatus.SwapScheduled,
currentStatus === SwapStatus.SwapScheduled ||
currentStatus === SwapStatus.ContractExecuted,
`Unexpected status transition for ${tag}`,
);
break;
Expand Down

0 comments on commit 041942e

Please sign in to comment.