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

Add Sui platform skeleton #161

Closed
wants to merge 1 commit into from
Closed
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
1,386 changes: 454 additions & 932 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
"platforms/algorand",
"platforms/algorand/protocols/core",
"platforms/algorand/protocols/tokenBridge",
"platforms/sui",
"platforms/sui/protocols/core",
"platforms/sui/protocols/tokenBridge",
"examples"
],
"unreleased": [
Expand Down
20 changes: 20 additions & 0 deletions platforms/sui/eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"env": {
"node": true
},
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"comma-dangle": ["error", "always-multiline"],
"semi": ["error", "always"],
"@typescript-eslint/explicit-module-boundary-types": ["error"],
"@typescript-eslint/no-non-null-assertion": ["error"],
"@typescript-eslint/no-explicit-any": ["error", { "ignoreRestArgs": true }]
}
}
48 changes: 48 additions & 0 deletions platforms/sui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@wormhole-foundation/connect-sdk-sui",
"version": "0.3.0-beta.3",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
},
"bugs": {
"url": "https://github.com/wormhole-foundation/connect-sdk/issues"
},
"homepage": "https://github.com/wormhole-foundation/connect-sdk#readme",
"directories": {
"test": "tests"
},
"license": "Apache-2.0",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/esm/index.d.ts",
"author": "",
"description": "SDK for EVM chains, used in conjunction with @wormhole-foundation/connect-sdk",
"files": [
"dist/**/*"
],
"keywords": [
"wormhole",
"sdk",
"typescript",
"connect",
"sui"
],
"engines": {
"node": ">=16"
},
"sideEffects": false,
"scripts": {
"build:cjs": "tsc -p ./tsconfig.cjs.json",
"build:esm": "tsc -p ./tsconfig.esm.json",
"build": "npm run build:cjs && npm run build:esm",
"rebuild": "npm run clean && npm run build:cjs && npm run build:esm",
"clean": "rm -rf ./dist && rm -f ./*.tsbuildinfo",
"lint": "npm run prettier && eslint --fix",
"prettier": "prettier --write ./src"
},
"dependencies": {
"@wormhole-foundation/connect-sdk": "^0.3.0-beta.3",
"@mysten/sui.js": "^0.32.2"
}
}
48 changes: 48 additions & 0 deletions platforms/sui/protocols/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@wormhole-foundation/connect-sdk-sui-core",
"version": "0.3.0-beta.3",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
},
"bugs": {
"url": "https://github.com/wormhole-foundation/connect-sdk/issues"
},
"homepage": "https://github.com/wormhole-foundation/connect-sdk#readme",
"directories": {
"test": "tests"
},
"license": "Apache-2.0",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/esm/index.d.ts",
"author": "",
"description": "SDK for Sui chains, used in conjunction with @wormhole-foundation/connect-sdk",
"files": [
"dist/**/*"
],
"keywords": [
"wormhole",
"sdk",
"typescript",
"connect",
"sui"
],
"engines": {
"node": ">=16"
},
"sideEffects": false,
"scripts": {
"build:cjs": "tsc -p ./tsconfig.cjs.json",
"build:esm": "tsc -p ./tsconfig.esm.json",
"build": "npm run build:cjs && npm run build:esm",
"rebuild": "npm run clean && npm run build:cjs && npm run build:esm",
"clean": "rm -rf ./dist && rm -f ./*.tsbuildinfo",
"lint": "npm run prettier && eslint --fix",
"prettier": "prettier --write ./src"
},
"dependencies": {
"@wormhole-foundation/connect-sdk": "^0.3.0-beta.3",
"@wormhole-foundation/connect-sdk-sui": "^0.3.0-beta.3"
}
}
72 changes: 72 additions & 0 deletions platforms/sui/protocols/core/src/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { JsonRpcProvider } from "@mysten/sui.js";
import {
AccountAddress,
ChainId,
ChainsConfig,
Contracts,
Network,
PayloadLiteral,
VAA,
WormholeCore,
WormholeMessageId,
toChainId,
} from "@wormhole-foundation/connect-sdk";
import {
AnySuiAddress,
SuiChains,
SuiPlatform,
SuiPlatformType,
SuiUnsignedTransaction,
} from "@wormhole-foundation/connect-sdk-sui";

export class SuiWormholeCore<N extends Network, C extends SuiChains>
implements WormholeCore<N, SuiPlatformType, C>
{
readonly chainId: ChainId;
readonly coreBridge: string;

private constructor(
readonly network: N,
readonly chain: C,
readonly connection: JsonRpcProvider,
readonly contracts: Contracts,
) {
this.chainId = toChainId(chain);
const coreBridgeAddress = contracts.coreBridge;
if (!coreBridgeAddress)
throw new Error(`CoreBridge contract Address for chain ${chain} not found`);
this.coreBridge = coreBridgeAddress;
}
getMessageFee(): Promise<bigint> {
throw new Error("Method not implemented.");
}

static async fromRpc<N extends Network>(
connection: JsonRpcProvider,
config: ChainsConfig<N, SuiPlatformType>,
) {
const [network, chain] = await SuiPlatform.chainFromRpc(connection);
const conf = config[chain]!;
if (conf.network !== network)
throw new Error(`Network mismatch: ${conf.network} !== ${network}`);
return new SuiWormholeCore(network as N, chain, connection, conf.contracts);
}

async *verifyMessage(
sender: AccountAddress<C>,
vaa: VAA<PayloadLiteral>,
): AsyncGenerator<SuiUnsignedTransaction<N, C>> {
throw new Error("Method not implemented.");
}

async *publishMessage(
sender: AnySuiAddress,
message: string | Uint8Array,
): AsyncGenerator<SuiUnsignedTransaction<N, C>> {
throw new Error("Method not implemented.");
}

async parseTransaction(txid: string): Promise<WormholeMessageId[]> {
throw new Error("Not implemented");
}
}
15 changes: 15 additions & 0 deletions platforms/sui/protocols/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { _platform } from "@wormhole-foundation/connect-sdk-sui";
import { registerProtocol } from "@wormhole-foundation/connect-sdk";
import { SuiWormholeCore } from "./core";

declare global {
namespace WormholeNamespace {
export interface PlatformToProtocolMapping {
Sui: {};
}
}
}

registerProtocol(_platform, "WormholeCore", SuiWormholeCore);

export * from "./core";
8 changes: 8 additions & 0 deletions platforms/sui/protocols/core/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../../../tsconfig.cjs.json",
"include": ["src"],
"compilerOptions": {
"outDir": "dist/cjs",
"rootDir": "src"
}
}
8 changes: 8 additions & 0 deletions platforms/sui/protocols/core/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../../../tsconfig.esm.json",
"include": ["src"],
"compilerOptions": {
"outDir": "dist/esm",
"rootDir": "src"
}
}
4 changes: 4 additions & 0 deletions platforms/sui/protocols/core/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["../../../../typedoc.base.json"],
"entryPoints": ["src/index.ts"],
}
48 changes: 48 additions & 0 deletions platforms/sui/protocols/tokenBridge/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@wormhole-foundation/connect-sdk-sui-tokenbridge",
"version": "0.3.0-beta.3",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
},
"bugs": {
"url": "https://github.com/wormhole-foundation/connect-sdk/issues"
},
"homepage": "https://github.com/wormhole-foundation/connect-sdk#readme",
"directories": {
"test": "tests"
},
"license": "Apache-2.0",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/esm/index.d.ts",
"author": "",
"description": "SDK for Sui chains, used in conjunction with @wormhole-foundation/connect-sdk",
"files": [
"dist/**/*"
],
"keywords": [
"wormhole",
"sdk",
"typescript",
"connect",
"sui"
],
"engines": {
"node": ">=16"
},
"sideEffects": false,
"scripts": {
"build:cjs": "tsc -p ./tsconfig.cjs.json",
"build:esm": "tsc -p ./tsconfig.esm.json",
"build": "npm run build:cjs && npm run build:esm",
"rebuild": "npm run clean && npm run build:cjs && npm run build:esm",
"clean": "rm -rf ./dist && rm -f ./*.tsbuildinfo",
"lint": "npm run prettier && eslint --fix",
"prettier": "prettier --write ./src"
},
"dependencies": {
"@wormhole-foundation/connect-sdk": "^0.3.0-beta.3",
"@wormhole-foundation/connect-sdk-sui": "^0.3.0-beta.3"
}
}
15 changes: 15 additions & 0 deletions platforms/sui/protocols/tokenBridge/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { _platform } from "@wormhole-foundation/connect-sdk-sui";
import { registerProtocol } from "@wormhole-foundation/connect-sdk";
import { SuiTokenBridge } from "./tokenBridge";

declare global {
namespace WormholeNamespace {
export interface PlatformToProtocolMapping {
Sui: {};
}
}
}

registerProtocol(_platform, "TokenBridge", SuiTokenBridge);

export * from "./tokenBridge";
Loading