Skip to content

Commit

Permalink
Check if already unlocked for posted order hashes (#16)
Browse files Browse the repository at this point in the history
Co-authored-by: mrlotfi <[email protected]>
mrlotfi and mrlotfi authored Oct 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 93b3822 commit 2687aec
Showing 3 changed files with 42 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/driver/state-closer.ts
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ export class StateCloser {
const serializedTrx = trx.serialize();

logger.info(`Closing ${destSolanaStates.length} dest swap states`);
await this.solanaTxSender.sendAndConfirmTransaction(serializedTrx, 10);
await this.solanaTxSender.sendAndConfirmTransaction(serializedTrx, 10, 'confirmed', 60, 100, false);
logger.info(`Closed ${destSolanaStates.length} dest swap states`);
}

@@ -73,7 +73,7 @@ export class StateCloser {
const serializedTrx = trx.serialize();

logger.info(`Closing ${auctionStates.length} auction states`);
await this.solanaTxSender.sendAndConfirmTransaction(serializedTrx, 10);
await this.solanaTxSender.sendAndConfirmTransaction(serializedTrx, 10, 'confirmed', 30, 100, false);
logger.info(`Closed ${auctionStates.length} auction states`);
}

54 changes: 38 additions & 16 deletions src/driver/unlocker.ts
Original file line number Diff line number Diff line change
@@ -90,22 +90,6 @@ export class Unlocker {
this.driverAddresses.push(this.walletConfig.evm.address);
}

private async getOwnedUnlockableSwaps(driverAddresses: string[]): Promise<{
singleData: UnlockableSwapSingleItem[];
batchData: UnlockableSwapBatchItem[];
postedBatchData: UnlockableSwapBatchItem[];
}> {
const rawData = await axios.get(this.endpoints.explorerApiUrl + '/v3/unlockable-swaps', {
params: {
batchUnlockThreshold: this.gConf.batchUnlockThreshold,
singleBatchChainIds: this.gConf.singleBatchChainIds.join(','),
driverAddresses: driverAddresses.join(','),
},
});

return rawData.data;
}

scheduleUnlockJobs() {
if (this.gConf.disableUnlocker) {
logger.info(`Unlocker is disabled and ignored.`);
@@ -164,6 +148,21 @@ export class Unlocker {
}

for (let postedUnlockData of freshExplorerData.postedBatchData) {
const orderHashs = postedUnlockData.orders.map((order) => order.orderHash);
let alreadyUnlocked: Set<string>;
if (+postedUnlockData.fromChain === CHAIN_ID_SOLANA) {
alreadyUnlocked = await this.getAlreadyUnlockedOrPendingOrderSolana(orderHashs);
} else {
alreadyUnlocked = await this.getAlreadyUnlockedOrPendingOrderEvm(
postedUnlockData.fromChain,
orderHashs,
);
}

postedUnlockData.orders = postedUnlockData.orders.filter(
(order) => !alreadyUnlocked.has(order.orderHash),
);

this.scheduleAlreadyPostedUnlocks(postedUnlockData);
}

@@ -366,6 +365,8 @@ export class Unlocker {
this.rpcConfig.solana.sendCount,
'confirmed',
30,
100,
false,
);

return txHash;
@@ -433,6 +434,9 @@ export class Unlocker {
serializedTrx,
this.rpcConfig.solana.sendCount,
'confirmed',
60,
100,
false,
);

return txHash;
@@ -601,6 +605,8 @@ export class Unlocker {
this.rpcConfig.solana.sendCount,
'confirmed',
30,
100,
false,
);
logger.verbose(`Batch posted Successfully Solana, getting batch sequence`);

@@ -746,6 +752,22 @@ export class Unlocker {
return result;
}

private async getOwnedUnlockableSwaps(driverAddresses: string[]): Promise<{
singleData: UnlockableSwapSingleItem[];
batchData: UnlockableSwapBatchItem[];
postedBatchData: UnlockableSwapBatchItem[];
}> {
const rawData = await axios.get(this.endpoints.explorerApiUrl + '/v3/unlockable-swaps', {
params: {
batchUnlockThreshold: this.gConf.batchUnlockThreshold,
singleBatchChainIds: this.gConf.singleBatchChainIds.join(','),
driverAddresses: driverAddresses.join(','),
},
});

return rawData.data;
}

private async getSignedVaa(sequence: string, destChainId: number, deadlineSeconds?: number): Promise<string> {
const contractAddress = this.contracts.contracts[destChainId];
let mayanBridgeEmitterAddress;
3 changes: 2 additions & 1 deletion src/utils/solana-trx.ts
Original file line number Diff line number Diff line change
@@ -260,13 +260,14 @@ export class SolanaMultiTxSender {
confirmationLevel: 'confirmed' | 'finalized' = 'confirmed',
timeoutSeconds: number = 59,
maxTotalSendCount: number = 150,
skipPreflightFirst: boolean = true,
): Promise<string> {
const sendInterval = this.rpcConfig.solana.sendInterval;
const otherSendInterval = this.rpcConfig.solana.otherSendInterval;

let ongoingSends: any[] = [];
let done = false;
const trxHash = await this.connection.sendRawTransaction(rawTrx, { skipPreflight: true });
const trxHash = await this.connection.sendRawTransaction(rawTrx, { skipPreflight: skipPreflightFirst });

let startTime = new Date().getTime();
const backgroundSend = async () => {

0 comments on commit 2687aec

Please sign in to comment.