Skip to content

Commit

Permalink
add sui platform skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin committed Dec 13, 2023
1 parent db6fd95 commit 519d4cd
Show file tree
Hide file tree
Showing 27 changed files with 1,267 additions and 3,670 deletions.
4,179 changes: 512 additions & 3,667 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"core/base",
"core/definitions",
"connect",
"platforms/sui",
"platforms/sui/protocols/core",
"platforms/sui/protocols/tokenBridge"
],
"nothing": [
"platforms/evm",
"platforms/evm/protocols/core",
"platforms/evm/protocols/tokenBridge",
Expand All @@ -49,9 +54,7 @@
"platforms/cosmwasm",
"platforms/cosmwasm/protocols/core",
"platforms/cosmwasm/protocols/tokenBridge",
"platforms/cosmwasm/protocols/ibc"
],
"unreleased": [
"platforms/cosmwasm/protocols/ibc",
"examples",
"core/tokenRegistry",
"platforms/aptos",
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 }]
}
}
51 changes: 51 additions & 0 deletions platforms/sui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@wormhole-foundation/connect-sdk-sui",
"version": "0.2.5",
"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/**/*",
"src/**/*"
],
"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",
"bump:beta": "bump prerelease",
"test": "jest --config ./jest.config.ts"
},
"dependencies": {
"@wormhole-foundation/connect-sdk": "^0.2.5",
"@mysten/sui.js": "^0.32.2"
}
}
50 changes: 50 additions & 0 deletions platforms/sui/protocols/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@wormhole-foundation/connect-sdk-sui-core",
"version": "0.2.5",
"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/**/*",
"src/**/*"
],
"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",
"bump:beta": "bump prerelease",
"prettier": "prettier --write ./src"
},
"dependencies": {
"@wormhole-foundation/connect-sdk": "^0.2.5",
"@wormhole-foundation/connect-sdk-sui": "^0.2.5"
}
}
62 changes: 62 additions & 0 deletions platforms/sui/protocols/core/src/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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,
} 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;
}

static async fromRpc<N extends Network>(
connection: JsonRpcProvider,
config: ChainsConfig<N, SuiPlatformType>,
): Promise<SuiWormholeCore<N, SuiChains>> {
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>) {
throw new Error("Method not implemented.");
}

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

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

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

registerProtocol("Sui", "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"],
}
50 changes: 50 additions & 0 deletions platforms/sui/protocols/tokenBridge/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@wormhole-foundation/connect-sdk-sui-tokenbridge",
"version": "0.2.5",
"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/**/*",
"src/**/*"
],
"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",
"bump:beta": "bump prerelease",
"prettier": "prettier --write ./src"
},
"dependencies": {
"@wormhole-foundation/connect-sdk": "^0.2.5",
"@wormhole-foundation/connect-sdk-sui": "^0.2.5"
}
}
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 { registerProtocol } from "@wormhole-foundation/connect-sdk";
import { SuiTokenBridge } from "./tokenBridge";
//import { SuiAutomaticTokenBridge } from "./automaticTokenBridge";

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

registerProtocol("Sui", "TokenBridge", SuiTokenBridge);

export * from "./tokenBridge";
Loading

0 comments on commit 519d4cd

Please sign in to comment.