Skip to content

Commit

Permalink
generate api reference
Browse files Browse the repository at this point in the history
  • Loading branch information
aelmanaa committed Jul 15, 2024
1 parent 29aed6e commit dad5228
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 19 deletions.
52 changes: 44 additions & 8 deletions api_reference/javascript/CCIPLocalSimulatorFork.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
</dd>
<dt>
<a href="#getEvm2EvmMessage">getEvm2EvmMessage(receipt)</a> ⇒{' '}
<code>object</code> | <code>null</code>
<code>
<a href="#Evm2EvmMessage">Evm2EvmMessage</a>
</code>{' '}
| <code>null</code>
</dt>
<dd>
<p>
Expand All @@ -33,6 +36,15 @@
</dd>
</dl>

## Typedefs

<dl>
<dt>
<a href="#Evm2EvmMessage">Evm2EvmMessage</a> : <code>Object</code>
</dt>
<dd></dd>
</dl>

<a name="requestLinkFromTheFaucet"></a>

## requestLinkFromTheFaucet(linkAddress, to, amount) ⇒ <code>Promise.&lt;string&gt;</code>
Expand All @@ -51,15 +63,16 @@ transaction hash of the fund transfer

<a name="getEvm2EvmMessage"></a>

## getEvm2EvmMessage(receipt) ⇒ <code>object</code> \| <code>null</code>
## getEvm2EvmMessage(receipt) ⇒ [<code>Evm2EvmMessage</code>](#Evm2EvmMessage) \| <code>null</code>

Parses a transaction receipt to extract the sent message Scans through
transaction logs to find a `CCIPSendRequested` event and then decodes it to an
object

**Kind**: global function
**Returns**: <code>object</code> \| <code>null</code> - Returns either the sent
message or null if provided receipt does not contain `CCIPSendRequested` log
**Returns**: [<code>Evm2EvmMessage</code>](#Evm2EvmMessage) \|
<code>null</code> - Returns either the sent message or null if provided receipt
does not contain `CCIPSendRequested` log

| Param | Type | Description |
| ------- | ------------------- | ------------------------------------------------ |
Expand All @@ -80,7 +93,30 @@ if the message is successfully routed, or reverts
- <code>Error</code> Fails if no off-ramp matches the message's source chain
selector or if calling `router.getOffRamps()`

| Param | Type | Description |
| -------------- | ------------------- | --------------------------------- |
| routerAddress | <code>string</code> | Address of the destination Router |
| evm2EvmMessage | <code>object</code> | Sent cross-chain message |
| Param | Type | Description |
| -------------- | ---------------------------------------------- | --------------------------------- |
| routerAddress | <code>string</code> | Address of the destination Router |
| evm2EvmMessage | [<code>Evm2EvmMessage</code>](#Evm2EvmMessage) | Sent cross-chain message |

<a name="Evm2EvmMessage"></a>

## Evm2EvmMessage : <code>Object</code>

**Kind**: global typedef
**Properties**

| Name | Type |
| ------------------- | ----------------------------------------------------------- |
| sourceChainSelector | <code>bigint</code> |
| sender | <code>string</code> |
| receiver | <code>string</code> |
| sequenceNumber | <code>bigint</code> |
| gasLimit | <code>bigint</code> |
| strict | <code>boolean</code> |
| nonce | <code>bigint</code> |
| feeToken | <code>string</code> |
| feeTokenAmount | <code>bigint</code> |
| data | <code>string</code> |
| tokenAmounts | <code>Array.&lt;\{token: string, amount: bigint}&gt;</code> |
| sourceTokenData | <code>Array.&lt;string&gt;</code> |
| messageId | <code>string</code> |
19 changes: 10 additions & 9 deletions helper_doc/generate-jsdoc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import fs from "fs-extra";
import path from "path";
import jsdoc2md from "jsdoc-to-markdown";
import fs from 'fs-extra';
import path from 'path';
import jsdoc2md from 'jsdoc-to-markdown';

const MDX_EXTENSION = ".mdx";
const outputDir = path.join(process.cwd(), "api_reference/javascript");
const MDX_EXTENSION = '.mdx';
const outputDir = path.join(process.cwd(), 'api_reference/javascript');

const jsFiles = ["scripts/CCIPLocalSimulatorFork.js"];
const jsFiles = ['scripts/CCIPLocalSimulatorFork.js'];

const generateMarkdownDocs = async (
files: string[],
Expand All @@ -21,10 +21,11 @@ const generateMarkdownDocs = async (
`${fileName}${MDX_EXTENSION}`
);
const markdown = await jsdoc2md.render({ files: absoluteFilePath });
await fs.outputFile(outputPath, markdown);
const fixedMarkdown = markdown.replace(/&lt;\{/g, '&lt;\\{');
await fs.outputFile(outputPath, fixedMarkdown);
}
};

generateMarkdownDocs(jsFiles, outputDir)
.then(() => console.log("Markdown documentation generated successfully."))
.catch((err) => console.error(err));
.then(() => console.log('Markdown documentation generated successfully.'))
.catch(err => console.error(err));
21 changes: 19 additions & 2 deletions scripts/CCIPLocalSimulatorFork.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,29 @@ async function requestLinkFromTheFaucet(linkAddress, to, amount) {
return tx.hash;
}

/**
* @typedef {Object} Evm2EvmMessage
* @property {bigint} sourceChainSelector
* @property {string} sender
* @property {string} receiver
* @property {bigint} sequenceNumber
* @property {bigint} gasLimit
* @property {boolean} strict
* @property {bigint} nonce
* @property {string} feeToken
* @property {bigint} feeTokenAmount
* @property {string} data
* @property {Array<{token: string, amount: bigint}>} tokenAmounts
* @property {Array<string>} sourceTokenData
* @property {string} messageId
*/

/**
* Parses a transaction receipt to extract the sent message
* Scans through transaction logs to find a `CCIPSendRequested` event and then decodes it to an object
*
* @param {object} receipt - The transaction receipt from the `ccipSend` call
* @returns {object | null} Returns either the sent message or null if provided receipt does not contain `CCIPSendRequested` log
* @returns {Evm2EvmMessage | null} Returns either the sent message or null if provided receipt does not contain `CCIPSendRequested` log
*/
function getEvm2EvmMessage(receipt) {
const evm2EvmOnRampInterface = new ethers.Interface(EVM2EVMOnRampAbi);
Expand Down Expand Up @@ -87,7 +104,7 @@ function getEvm2EvmMessage(receipt) {
* Routes the sent message from the source network on the destination (current) network
*
* @param {string} routerAddress - Address of the destination Router
* @param {object} evm2EvmMessage - Sent cross-chain message
* @param {Evm2EvmMessage} evm2EvmMessage - Sent cross-chain message
* @returns {Promise<void>} Either resolves with no value if the message is successfully routed, or reverts
* @throws {Error} Fails if no off-ramp matches the message's source chain selector or if calling `router.getOffRamps()`
*/
Expand Down

0 comments on commit dad5228

Please sign in to comment.