Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/hyperlane sdk #1

Merged
merged 5 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,15 @@ public-hoist-pattern[]='react'
public-hoist-pattern[]='react-dom'
public-hoist-pattern[]='@types/react'
public-hoist-pattern[]='@types/react-dom'
public-hoist-pattern[]='lit-html'
public-hoist-pattern[]='lit-html'

# Smart Contracts
public-hoist-pattern[]='hardhat'
public-hoist-pattern[]='@ethersproject/*'

# Inconsistencies in versions sometimes (prefer syncpack but this is an escape hatch)
public-hoist-pattern[]='viem'
public-hoist-pattern[]='@viem/viem'
public-hoist-pattern[]='wagmi'
public-hoist-pattern[]='@wagmi/*'
public-hoist-pattern[]='@rainbow-me/*'
6 changes: 6 additions & 0 deletions packages/hyperlane-contracts/.depcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ignores: [
"@types/node",
"vite",
"zod",
"@openzeppelin/contracts"
]
4 changes: 4 additions & 0 deletions packages/hyperlane-contracts/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ['@owlprotocol/eslint-config'],
};
77 changes: 77 additions & 0 deletions packages/hyperlane-contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

cache/

# dependencies
node_modules
.pnp
.pnp.js

# testing
coverage

# build outputs
.next/
out/
build
.build
.esbuild
dist
dist-ssr
lib
.serverless

# misc
.DS_Store
*.pem
.idea

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
logs
*.log

# local env files
.env.local
.env.development
.env.test
.env.production
.env

# turbo
.turbo

# local
*.local

# ipfs
.ipfs
.datastore
.datastore_fs
.datastore_level
.datastore_s3

# hardhat
typechain
cache
factory
/src/typechain
/src/artifacts
/src/zsol
/artifacts
/docs-contracts-reference/*
!/docs-contracts-reference/index.md
/scripts
traceOutputDir
src/deployments

# forge
forge-cache/
out/
soljson-v*.js
.openzeppelin/unknown-*.json
*.py
!.env.example
5 changes: 5 additions & 0 deletions packages/hyperlane-contracts/.lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"*.+(js|jsx)": ["eslint --fix"],
"*.+(ts|tsx)": ["eslint --fix"],
"*.+(json|css|md)": ["prettier --write"]
}
3 changes: 3 additions & 0 deletions packages/hyperlane-contracts/.prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require("@owlprotocol/prettier-config"),
};
7 changes: 7 additions & 0 deletions packages/hyperlane-contracts/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2024 Owl Protocol

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, libribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions packages/hyperlane-contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Hyperlane Contracts
23 changes: 23 additions & 0 deletions packages/hyperlane-contracts/contracts/exports.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

//Re-export & recompile contracts with increased optimization

//interfaces
import {IInterchainSecurityModule} from "@hyperlane-xyz/core/contracts/interfaces/IInterchainSecurityModule.sol";
import {IMailbox} from "@hyperlane-xyz/core/contracts/interfaces/IMailbox.sol";
import {IMessageRecipient} from "@hyperlane-xyz/core/contracts/interfaces/IMessageRecipient.sol";
import {IRouter} from "@hyperlane-xyz/core/contracts/interfaces/IRouter.sol";

import {IRoutingIsm} from "@hyperlane-xyz/core/contracts/interfaces/isms/IRoutingIsm.sol";

//implementations
import {Mailbox} from "@hyperlane-xyz/core/contracts/Mailbox.sol";
import {MailboxClient} from "@hyperlane-xyz/core/contracts/client/MailboxClient.sol";
import {Router} from "@hyperlane-xyz/core/contracts/client/Router.sol";

import {InterchainAccountRouter} from "@hyperlane-xyz/core/contracts/middleware/InterchainAccountRouter.sol";
import {InterchainQueryRouter} from "@hyperlane-xyz/core/contracts/middleware/InterchainQueryRouter.sol";
import {OwnableMulticall} from "@hyperlane-xyz/core/contracts/middleware/libs/OwnableMulticall.sol";

import {TrustedRelayerIsm} from "@hyperlane-xyz/core/contracts/isms/TrustedRelayerIsm.sol";
30 changes: 30 additions & 0 deletions packages/hyperlane-contracts/docs-templates/common.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{h}} {{name}}

{{#if signature}}
```solidity
{{{signature}}}
```
{{/if}}

{{{natspec.notice}}}

{{#if natspec.dev}}
{{#formatLinks}}{{{natspec.dev}}}{{/formatLinks}}
{{/if}}

{{#if natspec.params}}
| Name | Type | Description |
| ---- | ---- | ----------- |
{{#each params}}
| {{name}} | {{type}} | {{#formatLinks}}{{{joinLines natspec}}}{{/formatLinks}} |
{{/each}}
{{/if}}

{{#if natspec.returns}}
| Name | Type | Description |
| ---- | ---- | ----------- |
{{#each returns}}
| {{#if name}}{{name}}{{else}}[{{@index}}]{{/if}} | {{type}} | {{#formatLinks}}{{{joinLines natspec}}}{{/formatLinks}} |
{{/each}}
{{/if}}

8 changes: 8 additions & 0 deletions packages/hyperlane-contracts/docs-templates/contract.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{>common}}

{{#each items}}
{{#hsection}}
{{>item}}
{{/hsection}}

{{/each}}
9 changes: 9 additions & 0 deletions packages/hyperlane-contracts/docs-templates/enum.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{>common}}

```solidity
enum {{name}} {
{{#each members}}
{{name}}{{#unless @last}},{{/unless}}
{{/each}}
}
```
1 change: 1 addition & 0 deletions packages/hyperlane-contracts/docs-templates/error.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{>common}}
1 change: 1 addition & 0 deletions packages/hyperlane-contracts/docs-templates/event.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{>common}}
1 change: 1 addition & 0 deletions packages/hyperlane-contracts/docs-templates/function.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{>common}}
163 changes: 163 additions & 0 deletions packages/hyperlane-contracts/docs-templates/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import { HelperOptions, Utils } from 'handlebars';

// import { TypeName } from 'solidity-ast';
// import { DocItemWithContext } from '../../site';

/**
* Returns a Markdown heading marker. An optional number increases the heading level.
*
* Input Output
* {{h}} {{name}} # Name
* {{h 2}} {{name}} ## Name
*/
export function h(opts: HelperOptions): string;
export function h(hsublevel: number, opts: HelperOptions): string;
export function h(hsublevel: number | HelperOptions, opts?: HelperOptions) {
const { hlevel } = getHLevel(hsublevel, opts);
return new Array(hlevel).fill('#').join('');
};

/**
* Delineates a section where headings should be increased by 1 or a custom number.
*
* {{#hsection}}
* {{>partial-with-headings}}
* {{/hsection}}
*/
export function hsection(opts: HelperOptions): string;
export function hsection(hsublevel: number, opts: HelperOptions): string;
export function hsection(this: unknown, hsublevel: number | HelperOptions, opts?: HelperOptions) {
let hlevel;
({ hlevel, opts } = getHLevel(hsublevel, opts));
opts.data = Utils.createFrame(opts.data);
opts.data.hlevel = hlevel;
return opts.fn(this as unknown, opts);
}

/**
* Helper for dealing with the optional hsublevel argument.
*/
function getHLevel(hsublevel: number | HelperOptions, opts?: HelperOptions) {
if (typeof hsublevel === 'number') {
opts = opts!;
hsublevel = Math.max(1, hsublevel);
} else {
opts = hsublevel;
hsublevel = 1;
}
const contextHLevel: number = opts.data?.hlevel ?? 0;
return { opts, hlevel: contextHLevel + hsublevel };
}

export function trim(text: string) {
if (typeof text === 'string') {
return text.trim();
}
}

export function joinLines(text?: string) {
if (typeof text === 'string') {
return text.replace(/\n+/g, ' ');
}
}

// Regular expression -> match all function names, contract names, and # to separate
const re = /{([\-#a-zA-Z0-9_]*)}/gm;
const path = './'; // todo - set this somewhere else
export function formatLinks(this: unknown, opts: HelperOptions) {
// Render our text
let rendered = opts.fn(this as unknown, opts);
// Find all occurrences
const matches = rendered.match(re);
if (!matches) return rendered;

// Iterate through links and format
for (const match of matches) {
// {ContractA#mint} => ContractA#mint
let name = match.slice(1, match.length - 1);

// Standardize how it's formatted
// {ContractA-mint} => {ContractA#Mint}
if (name.includes('-')) name = name.replace('-', '#');

const link = getLink(name, path);

// Set md link and update
rendered = rendered.replace(match, link);
}

return rendered;
}

/**
* Returns displayName and resource for a given artifact name
*/
function getLink(name: string, path: string) {

let displayName = name;
let resource = '';
let link = '';

// ContractA#mint => Contract.mint(...)
displayName = displayName.replace('#', '.');

// Split up what we're referencing
// 'CrafterMint#deposit'.split('#') => ['CrafterMint', 'deposit']
const components = name.split('#');

// Add function display: deposit => deposit(...)
if (isFunction(components[components.length - 1]))
displayName += '(...)';

// Either an external contract (CaseSensitive) or a local function (alllowercase)
if (components.length == 1) {
// Check if we need to be lowercase (is an anchor)
if (isFunction(components[0])) {
components[0] = components[0].toLowerCase();
resource = '#' + components[0];
} else {
// Link to another page
resource = path + components[0];
}
} else if (components.length == 2) {
// Always an anchor, which must always be lower
components[1] = components[1].toLowerCase();

// See if we found an anchor type
if (isAnchor(name)) {
// Special local {#Anchor} type
displayName = displayName.slice(1); // slice off .
// We don't want to path anywhere else
path = '';
}

// Put everything back together to a link
resource = path + components.join('#');
} else {
// Unsupported format, just return
return name;
}

// Generate link
link = `[\`${displayName}\`](${resource})`;

return link;

}

/**
* Determines whether a specified text string is referencing a local function or
* a separate contract.
* {Contract#function} is not local
* {function} is local
*/
function isFunction(name: string) {
return (!name.includes('#') && name.length > 0 && name[0] === name[0].toLowerCase());
}

/**
* Identify local anchors by #Item
*/
function isAnchor(name: string) {
return (name[0] === '#');
}
1 change: 1 addition & 0 deletions packages/hyperlane-contracts/docs-templates/modifier.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{>common}}
6 changes: 6 additions & 0 deletions packages/hyperlane-contracts/docs-templates/page.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{#each items}}
{{#hsection}}
{{>item}}
{{/hsection}}

{{/each}}
9 changes: 9 additions & 0 deletions packages/hyperlane-contracts/docs-templates/struct.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{>common}}

```solidity
struct {{name}} {
{{#each members}}
{{{typeName.typeDescriptions.typeString}}} {{name}};
{{/each}}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{>common}}
1 change: 1 addition & 0 deletions packages/hyperlane-contracts/docs-templates/variable.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{>common}}
Loading
Loading