-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
19 changed files
with
179 additions
and
623 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {AbiParameter, decodeAbiParameters} from 'viem'; | ||
|
||
const responseDecoders: {[key: string]: AbiParameter[]} = { | ||
infra_src: [ | ||
{type: 'uint256', name: 'dstGasPrice'}, | ||
{type: 'uint256', name: 'srcGasPrice'}, | ||
{type: 'uint64', name: 'dstChainSelector'}, | ||
{type: 'uint256', name: 'linkUsdcRate'}, | ||
{type: 'uint256', name: 'nativeUsdcRate'}, | ||
{type: 'uint256', name: 'linkNativeRate'}, | ||
], | ||
infra_dst: [{type: 'uint256', name: 'messageId'}], | ||
pool_get_total_balance: [ | ||
{type: 'uint256', name: 'childPoolsLiquidity'}, | ||
{type: 'bytes1[]', name: 'depositsOnTheWayIdsToDelete'}, | ||
], | ||
pool_distribute_liq: [ | ||
{type: 'uint256', name: 'childPoolsLiquidity'}, | ||
{type: 'bytes1[]', name: 'depositsOnTheWayIdsToDelete'}, | ||
], | ||
}; | ||
/** | ||
* Decodes the response hex string based on the script name. | ||
* @param scriptName - The name of the script. | ||
* @param responseHex - The hex string response to decode. | ||
* @returns An object containing the decoded values. | ||
*/ | ||
export function decodeCLFResponse(scriptName: string, responseHex: string): any { | ||
const decoder = responseDecoders[scriptName]; | ||
if (!decoder) { | ||
console.error(`No decoder defined for script: ${scriptName}`); | ||
return null; | ||
} | ||
|
||
const responseData = responseHex.startsWith('0x') ? responseHex : '0x' + responseHex; | ||
|
||
try { | ||
const decodedValues = decodeAbiParameters(decoder, responseData); | ||
const result: Record<string, any> = {}; | ||
|
||
decoder.forEach((param, index) => { | ||
result[param.name || `param${index}`] = decodedValues[index]; | ||
}); | ||
|
||
return result; | ||
} catch (error) { | ||
console.error('Failed to decode response:', error); | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.