sygma-sdk icon indicating copy to clipboard operation
sygma-sdk copied to clipboard

SDK examples improvements for toNumber and FailToBridge status updated from Indexer

Open LyonSsS opened this issue 8 months ago • 0 comments

Context of toNumber: We are currently using this logic

if (!contractValueAfter.eq(valueBefore)) { console.log("Transaction successfully bridged."); console.log( Value after update: ${new Date( contractValueAfter.toNumber() ).toString()} ); break;

But the Sotrage Contract can generate a value like "161145517021206282627239951666939041182785141645" which may generate the following error when converted toNumber:

reason: 'overflow', code: 'NUMERIC_FAULT', fault: 'overflow', operation: 'toNumber', value: '161145517021206282627239951666939041182785141645'

Context of FailToBridge: We are currently using this logic to display status of a transaction

const id = setInterval(() => { getStatus(response.hash) .then((data) => { if (data[0]) { console.log("Status of the transfer", data[0].status); if(data[0].status == "executed") { clearInterval(id); process.exit(0); } } else { console.log("Waiting for the TX to be indexed"); } }) .catch((e) => { console.log("error:", e); }); }, 5000); }`

The problem of this logic is that if the Indexer does not report a problem ( aka there is an issue on relayer side and we do not execute), the example logs are going to execute continuously with "Waiting for the TX to be indexed" .

Also, this logic is not linked with the following method:

const waitUntilBridged = async ( valueBefore: BigNumber, intervalDuration: number = 15000, attempts: number = 8 ): Promise => { let i = 0; let contractValueAfter: BigNumber; for (;;) { await sleep(intervalDuration); contractValueAfter = await fetchAfterValue(); if (!contractValueAfter.eq(valueBefore)) { console.log("Transaction successfully bridged."); console.log( Value after update: ${new Date( contractValueAfter.toNumber() ).toString()} ); break; } i++; if (i > attempts) { // transaction should have been bridged already console.log("transaction is taking too much time to bridge!"); break; } } };

We should stop providing status ( probably with a bool flag) if this method goes on the "transaction is taking too much time to bridge!" logic ( so after attempts x duration)

LyonSsS avatar Jun 05 '24 14:06 LyonSsS