clients/js - initial near commit (#1442)

This commit is contained in:
Paul Noel 2022-08-19 15:29:57 +00:00 committed by GitHub
parent 338e6f2648
commit bf45b02c0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 469 additions and 45 deletions

View File

@ -9,6 +9,7 @@ import {
assertEVMChain,
CONTRACTS,
setDefaultWasm,
hexToUint8Array,
} from "@certusone/wormhole-sdk";
import { execute_solana } from "./solana";
import {
@ -19,6 +20,7 @@ import {
setStorageAt,
} from "./evm";
import { execute_terra } from "./terra";
import { execute_near } from "./near";
import * as vaa from "./vaa";
import { impossible, Payload, serialiseVAA, VAA } from "./vaa";
import {
@ -604,12 +606,12 @@ yargs(hideBin(process.argv))
);
} else if (isTerraChain(chain)) {
await execute_terra(parsed_vaa.payload, buf, network, chain);
} else if (chain === "solana") {
await execute_solana(parsed_vaa, buf, network);
} else if (chain === "solana" || chain === "pythnet") {
await execute_solana(parsed_vaa, buf, network, chain);
} else if (chain === "algorand") {
throw Error("Algorand is not supported yet");
} else if (chain === "near") {
throw Error("NEAR is not supported yet");
await execute_near(parsed_vaa.payload, vaa_hex, network);
} else if (chain === "injective") {
throw Error("INJECTIVE is not supported yet");
} else if (chain === "osmosis") {
@ -618,6 +620,8 @@ yargs(hideBin(process.argv))
throw Error("SUI is not supported yet");
} else if (chain === "aptos") {
throw Error("APTOS is not supported yet");
} else if (chain === "wormholechain") {
throw Error("wormholechain is not supported yet");
} else {
// If you get a type error here, hover over `chain`'s type and it tells you
// which cases are not handled
@ -641,13 +645,13 @@ function parseAddress(chain: ChainName, address: string): string {
return "0x" + evm_address(address);
} else if (isTerraChain(chain)) {
return "0x" + toHex(fromBech32(address).data).padStart(64, "0");
} else if (chain === "solana") {
} else if (chain === "solana" || chain === "pythnet") {
return "0x" + toHex(base58.decode(address)).padStart(64, "0");
} else if (chain === "algorand") {
// TODO: is there a better native format for algorand?
return "0x" + evm_address(address);
} else if (chain === "near") {
throw Error("NEAR is not supported yet");
return "0x" + evm_address(address);
} else if (chain === "injective") {
throw Error("INJECTIVE is not supported yet");
} else if (chain === "osmosis") {
@ -656,6 +660,8 @@ function parseAddress(chain: ChainName, address: string): string {
throw Error("SUI is not supported yet");
} else if (chain === "aptos") {
throw Error("APTOS is not supported yet");
} else if (chain === "wormholechain") {
throw Error("wormholechain is not supported yet");
} else {
impossible(chain);
}

124
clients/js/near.ts Normal file
View File

@ -0,0 +1,124 @@
import { impossible, Payload } from "./vaa";
import { NETWORKS } from "./networks";
import { CONTRACTS } from "@certusone/wormhole-sdk";
const BN = require("bn.js");
const nearAPI = require("near-api-js");
export async function execute_near(
payload: Payload,
vaa: string,
network: "MAINNET" | "TESTNET" | "DEVNET"
) {
let n = NETWORKS[network]["near"];
let contracts = CONTRACTS[network]["near"];
let account: string;
switch (payload.module) {
case "Core":
if (contracts.core === undefined) {
throw new Error("Core bridge not supported yet for near");
}
account = "wormhole." + n.baseAccount;
switch (payload.type) {
case "GuardianSetUpgrade":
console.log("Submitting new guardian set");
break;
case "ContractUpgrade":
console.log("Upgrading core contract");
break;
default:
impossible(payload);
}
break;
case "NFTBridge":
if (contracts.nft_bridge === undefined) {
throw new Error("NFT bridge not supported yet for near");
}
account = "nft." + n.baseAccount;
switch (payload.type) {
case "ContractUpgrade":
console.log("Upgrading contract");
break;
case "RegisterChain":
console.log("Registering chain");
break;
case "Transfer":
console.log("Completing transfer");
break;
default:
impossible(payload);
}
break;
case "TokenBridge":
account = "token." + n.baseAccount;
switch (payload.type) {
case "ContractUpgrade":
console.log("Upgrading contract");
break;
case "RegisterChain":
console.log("Registering chain");
break;
case "Transfer":
console.log("Completing transfer");
break;
case "AttestMeta":
console.log("Creating wrapped token");
break;
case "TransferWithPayload":
throw Error("Can't complete payload 3 transfer from CLI");
default:
impossible(payload);
break;
}
break;
default:
impossible(payload);
}
let target_contract = account;
let key = nearAPI.utils.KeyPair.fromString(n.key);
let keyStore = new nearAPI.keyStores.InMemoryKeyStore();
keyStore.setKey(n.networkId, account, key);
let near = await nearAPI.connect({
deps: {
keyStore,
},
networkId: n.networkId,
nodeUrl: n.rpc,
});
let nearAccount = new nearAPI.Account(near.connection, account);
console.log("submitting vaa the first time");
let result1 = await nearAccount.functionCall({
contractId: target_contract,
methodName: "submit_vaa",
args: {
vaa: vaa,
},
attachedDeposit: new BN("100000000000000000000000"),
gas: new BN("300000000000000"),
});
// You have to feed a vaa twice into the contract (two submits),
// The first time, it checks if it has been seen at all.
// The second time, it executes.
console.log("submitting vaa the second time");
let result2 = await nearAccount.functionCall({
contractId: target_contract,
methodName: "submit_vaa",
args: {
vaa: vaa,
},
attachedDeposit: new BN("100000000000000000000000"),
gas: new BN("300000000000000"),
});
let txHash = result1.transaction.hash + ":" + result2.transaction.hash;
console.log("Hash: " + txHash);
}

View File

@ -81,6 +81,8 @@ const MAINNET = {
near: {
rpc: undefined,
key: undefined,
networkId: "",
baseAccount: "",
},
injective: {
rpc: undefined,
@ -98,6 +100,14 @@ const MAINNET = {
rpc: undefined,
key: undefined,
},
pythnet: {
rpc: "http://api.pythnet.pyth.network:8899/",
key: get_env_var("SOLANA_KEY"),
},
wormholechain: {
rpc: undefined,
key: undefined,
},
moonbeam: {
rpc: "https://rpc.api.moonbeam.network",
key: get_env_var("ETH_KEY"),
@ -136,7 +146,7 @@ const TESTNET = {
},
solana: {
rpc: "https://api.devnet.solana.com",
key: get_env_var("SOLANA_KEY"),
key: get_env_var("SOLANA_KEY_TESTNET"),
},
terra: {
rpc: "https://bombay-lcd.terra.dev",
@ -192,8 +202,10 @@ const TESTNET = {
key: get_env_var("ETH_KEY_TESTNET"),
},
near: {
rpc: undefined,
key: undefined,
rpc: "https://rpc.testnet.near.org",
key: get_env_var("NEAR_KEY_TESTNET"),
networkId: "testnet",
baseAccount: "wormhole.testnet",
},
injective: {
rpc: undefined,
@ -211,6 +223,14 @@ const TESTNET = {
rpc: undefined,
key: undefined,
},
pythnet: {
rpc: "https://api.pythtest.pyth.network/",
key: get_env_var("SOLANA_KEY_TESTNET"),
},
wormholechain: {
rpc: undefined,
key: undefined,
},
moonbeam: {
rpc: "https://rpc.api.moonbase.moonbeam.network",
key: get_env_var("ETH_KEY_TESTNET"),
@ -307,6 +327,8 @@ const DEVNET = {
near: {
rpc: undefined,
key: undefined,
networkId: "sandbox",
baseAccount: "test.near",
},
injective: {
rpc: undefined,
@ -324,6 +346,14 @@ const DEVNET = {
rpc: undefined,
key: undefined,
},
pythnet: {
rpc: undefined,
key: undefined,
},
wormholechain: {
rpc: undefined,
key: undefined,
},
moonbeam: {
rpc: undefined,
key: "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d",

View File

@ -9,7 +9,7 @@
"version": "1.0.0",
"dependencies": {
"@celo-tools/celo-ethers-wrapper": "^0.1.0",
"@certusone/wormhole-sdk": "^0.4.5",
"@certusone/wormhole-sdk": "^0.6.2",
"@cosmjs/encoding": "^0.26.2",
"@solana/web3.js": "^1.22.0",
"@terra-money/terra.js": "^3.1.3",
@ -21,6 +21,7 @@
"dotenv": "^10.0.0",
"ethers": "^5.4.1",
"js-base64": "^3.6.1",
"near-api-js": "^0.45.1",
"npm": "^7.20.0",
"web3": "^1.5.0",
"yargs": "^17.0.1"
@ -543,20 +544,78 @@
}
},
"node_modules/@certusone/wormhole-sdk": {
"version": "0.4.5",
"resolved": "https://registry.npmjs.org/@certusone/wormhole-sdk/-/wormhole-sdk-0.4.5.tgz",
"integrity": "sha512-Wx726yI7zTIaDM2h/Ffrz3tjCKh4ZO5PDvwq/m5iVv6HqnL6xjrS6g8Qnq/K68cOMIJcxrqLW2SNl3vLUMLT7w==",
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/@certusone/wormhole-sdk/-/wormhole-sdk-0.6.2.tgz",
"integrity": "sha512-NHQVCZiV6Z+ZV498dANLj3iF3jR+w2L4g1JS6VPzt7aiKKmaupdDPDkNQI8AWIeO0xjvV4aMIagGi36ybBIBGA==",
"dependencies": {
"@improbable-eng/grpc-web": "^0.14.0",
"@certusone/wormhole-sdk-proto-web": "^0.0.3",
"@certusone/wormhole-sdk-wasm": "^0.0.1",
"@solana/spl-token": "^0.1.8",
"@solana/web3.js": "^1.24.0",
"@terra-money/terra.js": "^3.1.3",
"algosdk": "^1.15.0",
"axios": "^0.24.0",
"bech32": "^2.0.0",
"js-base64": "^3.6.1",
"protobufjs": "^6.11.2",
"rxjs": "^7.3.0"
"js-base64": "^3.6.1"
}
},
"node_modules/@certusone/wormhole-sdk-proto-web": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/@certusone/wormhole-sdk-proto-web/-/wormhole-sdk-proto-web-0.0.3.tgz",
"integrity": "sha512-O8gx8dLTcgF5jbmWjRiyZAn1LozslhWqDo6Q6QJfRiL6DWySV5TOXqgaEfQ4UGEM4uqM76HWZpwfEWUjaRhJ/A==",
"dependencies": {
"@improbable-eng/grpc-web": "^0.15.0",
"protobufjs": "^7.0.0",
"rxjs": "^7.5.6"
}
},
"node_modules/@certusone/wormhole-sdk-proto-web/node_modules/@improbable-eng/grpc-web": {
"version": "0.15.0",
"resolved": "https://registry.npmjs.org/@improbable-eng/grpc-web/-/grpc-web-0.15.0.tgz",
"integrity": "sha512-ERft9/0/8CmYalqOVnJnpdDry28q+j+nAlFFARdjyxXDJ+Mhgv9+F600QC8BR9ygOfrXRlAk6CvST2j+JCpQPg==",
"dependencies": {
"browser-headers": "^0.4.1"
},
"peerDependencies": {
"google-protobuf": "^3.14.0"
}
},
"node_modules/@certusone/wormhole-sdk-proto-web/node_modules/long": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/long/-/long-5.2.0.tgz",
"integrity": "sha512-9RTUNjK60eJbx3uz+TEGF7fUr29ZDxR5QzXcyDpeSfeH28S9ycINflOgOlppit5U+4kNTe83KQnMEerw7GmE8w=="
},
"node_modules/@certusone/wormhole-sdk-proto-web/node_modules/protobufjs": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.0.0.tgz",
"integrity": "sha512-ffNIEm+quOcYtQvHdW406v1NQmZSuqVklxsXk076BtuFnlYZfigLU+JOMrTD8TUOyqHYbRI/fSVNvgd25YeN3w==",
"hasInstallScript": true,
"dependencies": {
"@protobufjs/aspromise": "^1.1.2",
"@protobufjs/base64": "^1.1.2",
"@protobufjs/codegen": "^2.0.4",
"@protobufjs/eventemitter": "^1.1.0",
"@protobufjs/fetch": "^1.1.0",
"@protobufjs/float": "^1.0.2",
"@protobufjs/inquire": "^1.1.0",
"@protobufjs/path": "^1.1.2",
"@protobufjs/pool": "^1.1.0",
"@protobufjs/utf8": "^1.1.0",
"@types/long": "^4.0.1",
"@types/node": ">=13.7.0",
"long": "^5.0.0"
},
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/@certusone/wormhole-sdk-wasm": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/@certusone/wormhole-sdk-wasm/-/wormhole-sdk-wasm-0.0.1.tgz",
"integrity": "sha512-LdIwLhOyr4pPs2jqYubqC7d4UkqYBX0EG/ppspQlW3qlVE0LZRMrH6oVzzLMyHtV0Rw7O9sIKzORW/T3mrJv2w==",
"dependencies": {
"@types/long": "^4.0.2",
"@types/node": "^18.0.3"
}
},
"node_modules/@certusone/wormhole-sdk/node_modules/bech32": {
@ -2012,8 +2071,9 @@
"integrity": "sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA=="
},
"node_modules/@types/node": {
"version": "16.4.1",
"license": "MIT"
"version": "18.7.6",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.6.tgz",
"integrity": "sha512-EdxgKRXgYsNITy5mjjXjVE/CS8YENSdhiagGrLqjG0pvA2owgJ6i4l7wy/PFZGC0B1/H20lWKN7ONVDNYDZm7A=="
},
"node_modules/@types/pbkdf2": {
"version": "3.1.0",
@ -2780,6 +2840,11 @@
"url": "https://opencollective.com/browserslist"
}
},
"node_modules/capability": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/capability/-/capability-0.2.5.tgz",
"integrity": "sha512-rsJZYVCgXd08sPqwmaIqjAd5SUTfonV0z/gDJ8D6cN8wQphky1kkAYEqQ+hmDxTw7UihvBfjUVUSY+DBEe44jg=="
},
"node_modules/caseless": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
@ -3447,6 +3512,16 @@
"errno": "cli.js"
}
},
"node_modules/error-polyfill": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/error-polyfill/-/error-polyfill-0.1.3.tgz",
"integrity": "sha512-XHJk60ufE+TG/ydwp4lilOog549iiQF2OAPhkk9DdiYWMrltz5yhDz/xnKuenNwP7gy3dsibssO5QpVhkrSzzg==",
"dependencies": {
"capability": "^0.2.5",
"o3": "^1.0.3",
"u3": "^0.1.1"
}
},
"node_modules/es-abstract": {
"version": "1.18.5",
"resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.5.tgz",
@ -5737,6 +5812,14 @@
"buffer": "^5.5.0"
}
},
"node_modules/mustache": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz",
"integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==",
"bin": {
"mustache": "bin/mustache"
}
},
"node_modules/nan": {
"version": "2.15.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz",
@ -5747,6 +5830,42 @@
"resolved": "https://registry.npmjs.org/nano-json-stream-parser/-/nano-json-stream-parser-0.1.2.tgz",
"integrity": "sha1-DMj20OK2IrR5xA1JnEbWS3Vcb18="
},
"node_modules/near-api-js": {
"version": "0.45.1",
"resolved": "https://registry.npmjs.org/near-api-js/-/near-api-js-0.45.1.tgz",
"integrity": "sha512-QyPO/vjvMFlcMO1DCpsqzmnSqPIyHsjK1Qi4B5ZR1cJCIWMkqugDF/TDf8FVQ85pmlcYeYwfiTqKanKz+3IG0A==",
"dependencies": {
"bn.js": "5.2.0",
"borsh": "^0.7.0",
"bs58": "^4.0.0",
"depd": "^2.0.0",
"error-polyfill": "^0.1.3",
"http-errors": "^1.7.2",
"js-sha256": "^0.9.0",
"mustache": "^4.0.0",
"node-fetch": "^2.6.1",
"text-encoding-utf-8": "^1.0.2",
"tweetnacl": "^1.0.1"
}
},
"node_modules/near-api-js/node_modules/borsh": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/borsh/-/borsh-0.7.0.tgz",
"integrity": "sha512-CLCsZGIBCFnPtkNnieW/a8wmreDmfUtjU2m9yHrzPXIlNbqVs0AQrSatSG6vdNYUqdc83tkQi2eHfF98ubzQLA==",
"dependencies": {
"bn.js": "^5.2.0",
"bs58": "^4.0.0",
"text-encoding-utf-8": "^1.0.2"
}
},
"node_modules/near-api-js/node_modules/depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/negotiator": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
@ -5766,7 +5885,6 @@
},
"node_modules/node-fetch": {
"version": "2.6.1",
"dev": true,
"license": "MIT",
"engines": {
"node": "4.x || >=6.0.0"
@ -8453,6 +8571,14 @@
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz",
"integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU="
},
"node_modules/o3": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/o3/-/o3-1.0.3.tgz",
"integrity": "sha512-f+4n+vC6s4ysy7YO7O2gslWZBUu8Qj2i2OUJOvjRxQva7jVjYjB29jrr9NCjmxZQR0gzrOcv1RnqoYOeMs5VRQ==",
"dependencies": {
"capability": "^0.2.5"
}
},
"node_modules/oauth-sign": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
@ -8986,9 +9112,9 @@
"dev": true
},
"node_modules/rxjs": {
"version": "7.5.5",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.5.tgz",
"integrity": "sha512-sy+H0pQofO95VDmFLzyaw9xNJU4KTRSwQIGM6+iG3SypAtCiLDzpeG8sJrNCWn2Up9km+KhkvTdbkrdy+yzZdw==",
"version": "7.5.6",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.6.tgz",
"integrity": "sha512-dnyv2/YsXhnm461G+R/Pe5bWP41Nm6LBXEYWI6eiFP4fiwx6WRI/CD0zbdVAudd9xwLEF2IDcKXLHit0FYjUzw==",
"dependencies": {
"tslib": "^2.1.0"
}
@ -9769,6 +9895,11 @@
"node": ">=4.2.0"
}
},
"node_modules/u3": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/u3/-/u3-0.1.1.tgz",
"integrity": "sha512-+J5D5ir763y+Am/QY6hXNRlwljIeRMZMGs0cT6qqZVVzzT3X3nFPXVyPOFRMOR4kupB0T8JnCdpWdp6Q/iXn3w=="
},
"node_modules/ultron": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz",
@ -10949,20 +11080,19 @@
"requires": {}
},
"@certusone/wormhole-sdk": {
"version": "0.4.5",
"resolved": "https://registry.npmjs.org/@certusone/wormhole-sdk/-/wormhole-sdk-0.4.5.tgz",
"integrity": "sha512-Wx726yI7zTIaDM2h/Ffrz3tjCKh4ZO5PDvwq/m5iVv6HqnL6xjrS6g8Qnq/K68cOMIJcxrqLW2SNl3vLUMLT7w==",
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/@certusone/wormhole-sdk/-/wormhole-sdk-0.6.2.tgz",
"integrity": "sha512-NHQVCZiV6Z+ZV498dANLj3iF3jR+w2L4g1JS6VPzt7aiKKmaupdDPDkNQI8AWIeO0xjvV4aMIagGi36ybBIBGA==",
"requires": {
"@improbable-eng/grpc-web": "^0.14.0",
"@certusone/wormhole-sdk-proto-web": "^0.0.3",
"@certusone/wormhole-sdk-wasm": "^0.0.1",
"@solana/spl-token": "^0.1.8",
"@solana/web3.js": "^1.24.0",
"@terra-money/terra.js": "^3.1.3",
"algosdk": "^1.15.0",
"axios": "^0.24.0",
"bech32": "^2.0.0",
"js-base64": "^3.6.1",
"protobufjs": "^6.11.2",
"rxjs": "^7.3.0"
"js-base64": "^3.6.1"
},
"dependencies": {
"bech32": {
@ -10972,6 +11102,60 @@
}
}
},
"@certusone/wormhole-sdk-proto-web": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/@certusone/wormhole-sdk-proto-web/-/wormhole-sdk-proto-web-0.0.3.tgz",
"integrity": "sha512-O8gx8dLTcgF5jbmWjRiyZAn1LozslhWqDo6Q6QJfRiL6DWySV5TOXqgaEfQ4UGEM4uqM76HWZpwfEWUjaRhJ/A==",
"requires": {
"@improbable-eng/grpc-web": "^0.15.0",
"protobufjs": "^7.0.0",
"rxjs": "^7.5.6"
},
"dependencies": {
"@improbable-eng/grpc-web": {
"version": "0.15.0",
"resolved": "https://registry.npmjs.org/@improbable-eng/grpc-web/-/grpc-web-0.15.0.tgz",
"integrity": "sha512-ERft9/0/8CmYalqOVnJnpdDry28q+j+nAlFFARdjyxXDJ+Mhgv9+F600QC8BR9ygOfrXRlAk6CvST2j+JCpQPg==",
"requires": {
"browser-headers": "^0.4.1"
}
},
"long": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/long/-/long-5.2.0.tgz",
"integrity": "sha512-9RTUNjK60eJbx3uz+TEGF7fUr29ZDxR5QzXcyDpeSfeH28S9ycINflOgOlppit5U+4kNTe83KQnMEerw7GmE8w=="
},
"protobufjs": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.0.0.tgz",
"integrity": "sha512-ffNIEm+quOcYtQvHdW406v1NQmZSuqVklxsXk076BtuFnlYZfigLU+JOMrTD8TUOyqHYbRI/fSVNvgd25YeN3w==",
"requires": {
"@protobufjs/aspromise": "^1.1.2",
"@protobufjs/base64": "^1.1.2",
"@protobufjs/codegen": "^2.0.4",
"@protobufjs/eventemitter": "^1.1.0",
"@protobufjs/fetch": "^1.1.0",
"@protobufjs/float": "^1.0.2",
"@protobufjs/inquire": "^1.1.0",
"@protobufjs/path": "^1.1.2",
"@protobufjs/pool": "^1.1.0",
"@protobufjs/utf8": "^1.1.0",
"@types/long": "^4.0.1",
"@types/node": ">=13.7.0",
"long": "^5.0.0"
}
}
}
},
"@certusone/wormhole-sdk-wasm": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/@certusone/wormhole-sdk-wasm/-/wormhole-sdk-wasm-0.0.1.tgz",
"integrity": "sha512-LdIwLhOyr4pPs2jqYubqC7d4UkqYBX0EG/ppspQlW3qlVE0LZRMrH6oVzzLMyHtV0Rw7O9sIKzORW/T3mrJv2w==",
"requires": {
"@types/long": "^4.0.2",
"@types/node": "^18.0.3"
}
},
"@cosmjs/encoding": {
"version": "0.26.8",
"resolved": "https://registry.npmjs.org/@cosmjs/encoding/-/encoding-0.26.8.tgz",
@ -12018,7 +12202,9 @@
"integrity": "sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA=="
},
"@types/node": {
"version": "16.4.1"
"version": "18.7.6",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.6.tgz",
"integrity": "sha512-EdxgKRXgYsNITy5mjjXjVE/CS8YENSdhiagGrLqjG0pvA2owgJ6i4l7wy/PFZGC0B1/H20lWKN7ONVDNYDZm7A=="
},
"@types/pbkdf2": {
"version": "3.1.0",
@ -12628,6 +12814,11 @@
"integrity": "sha512-vcX4U8lwVXPdqzPWi6cAJ3FnQaqXbBqy/GZseKNQzRj37J7qZdGcBtxq/QLFNLLlfsoXLUdHw8Iwenri86Tagw==",
"dev": true
},
"capability": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/capability/-/capability-0.2.5.tgz",
"integrity": "sha512-rsJZYVCgXd08sPqwmaIqjAd5SUTfonV0z/gDJ8D6cN8wQphky1kkAYEqQ+hmDxTw7UihvBfjUVUSY+DBEe44jg=="
},
"caseless": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
@ -13201,6 +13392,16 @@
"prr": "~1.0.1"
}
},
"error-polyfill": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/error-polyfill/-/error-polyfill-0.1.3.tgz",
"integrity": "sha512-XHJk60ufE+TG/ydwp4lilOog549iiQF2OAPhkk9DdiYWMrltz5yhDz/xnKuenNwP7gy3dsibssO5QpVhkrSzzg==",
"requires": {
"capability": "^0.2.5",
"o3": "^1.0.3",
"u3": "^0.1.1"
}
},
"es-abstract": {
"version": "1.18.5",
"resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.5.tgz",
@ -15117,6 +15318,11 @@
}
}
},
"mustache": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz",
"integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ=="
},
"nan": {
"version": "2.15.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz",
@ -15127,6 +15333,41 @@
"resolved": "https://registry.npmjs.org/nano-json-stream-parser/-/nano-json-stream-parser-0.1.2.tgz",
"integrity": "sha1-DMj20OK2IrR5xA1JnEbWS3Vcb18="
},
"near-api-js": {
"version": "0.45.1",
"resolved": "https://registry.npmjs.org/near-api-js/-/near-api-js-0.45.1.tgz",
"integrity": "sha512-QyPO/vjvMFlcMO1DCpsqzmnSqPIyHsjK1Qi4B5ZR1cJCIWMkqugDF/TDf8FVQ85pmlcYeYwfiTqKanKz+3IG0A==",
"requires": {
"bn.js": "5.2.0",
"borsh": "^0.7.0",
"bs58": "^4.0.0",
"depd": "^2.0.0",
"error-polyfill": "^0.1.3",
"http-errors": "^1.7.2",
"js-sha256": "^0.9.0",
"mustache": "^4.0.0",
"node-fetch": "^2.6.1",
"text-encoding-utf-8": "^1.0.2",
"tweetnacl": "^1.0.1"
},
"dependencies": {
"borsh": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/borsh/-/borsh-0.7.0.tgz",
"integrity": "sha512-CLCsZGIBCFnPtkNnieW/a8wmreDmfUtjU2m9yHrzPXIlNbqVs0AQrSatSG6vdNYUqdc83tkQi2eHfF98ubzQLA==",
"requires": {
"bn.js": "^5.2.0",
"bs58": "^4.0.0",
"text-encoding-utf-8": "^1.0.2"
}
},
"depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw=="
}
}
},
"negotiator": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
@ -15141,8 +15382,7 @@
"version": "2.0.2"
},
"node-fetch": {
"version": "2.6.1",
"dev": true
"version": "2.6.1"
},
"node-gyp-build": {
"version": "4.2.3"
@ -17002,6 +17242,14 @@
}
}
},
"o3": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/o3/-/o3-1.0.3.tgz",
"integrity": "sha512-f+4n+vC6s4ysy7YO7O2gslWZBUu8Qj2i2OUJOvjRxQva7jVjYjB29jrr9NCjmxZQR0gzrOcv1RnqoYOeMs5VRQ==",
"requires": {
"capability": "^0.2.5"
}
},
"oauth-sign": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
@ -17429,9 +17677,9 @@
"dev": true
},
"rxjs": {
"version": "7.5.5",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.5.tgz",
"integrity": "sha512-sy+H0pQofO95VDmFLzyaw9xNJU4KTRSwQIGM6+iG3SypAtCiLDzpeG8sJrNCWn2Up9km+KhkvTdbkrdy+yzZdw==",
"version": "7.5.6",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.6.tgz",
"integrity": "sha512-dnyv2/YsXhnm461G+R/Pe5bWP41Nm6LBXEYWI6eiFP4fiwx6WRI/CD0zbdVAudd9xwLEF2IDcKXLHit0FYjUzw==",
"requires": {
"tslib": "^2.1.0"
}
@ -17993,6 +18241,11 @@
"integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==",
"dev": true
},
"u3": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/u3/-/u3-0.1.1.tgz",
"integrity": "sha512-+J5D5ir763y+Am/QY6hXNRlwljIeRMZMGs0cT6qqZVVzzT3X3nFPXVyPOFRMOR4kupB0T8JnCdpWdp6Q/iXn3w=="
},
"ultron": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz",

View File

@ -3,9 +3,9 @@
"version": "1.0.0",
"dependencies": {
"@celo-tools/celo-ethers-wrapper": "^0.1.0",
"@certusone/wormhole-sdk": "^0.4.5",
"@solana/web3.js": "^1.22.0",
"@certusone/wormhole-sdk": "^0.6.2",
"@cosmjs/encoding": "^0.26.2",
"@solana/web3.js": "^1.22.0",
"@terra-money/terra.js": "^3.1.3",
"axios": "^0.24.0",
"binary-parser": "^2.0.2",
@ -15,6 +15,7 @@
"dotenv": "^10.0.0",
"ethers": "^5.4.1",
"js-base64": "^3.6.1",
"near-api-js": "^0.45.1",
"npm": "^7.20.0",
"web3": "^1.5.0",
"yargs": "^17.0.1"

View File

@ -2,25 +2,29 @@ import * as web3s from '@solana/web3.js'
import { NETWORKS } from "./networks";
import { impossible, Payload, VAA } from "./vaa";
import base58 from "bs58";
import { CHAIN_ID_SOLANA, importCoreWasm, importNftWasm, importTokenWasm, ixFromRust } from "@certusone/wormhole-sdk";
import { CHAINS, importCoreWasm, importNftWasm, importTokenWasm, ixFromRust, SolanaChainName } from "@certusone/wormhole-sdk";
import { CONTRACTS } from "@certusone/wormhole-sdk"
import { postVaaSolanaWithRetry } from "@certusone/wormhole-sdk"
export async function execute_solana(
v: VAA<Payload>,
vaa: Buffer,
network: "MAINNET" | "TESTNET" | "DEVNET"
network: "MAINNET" | "TESTNET" | "DEVNET",
chain: SolanaChainName
) {
let ix: web3s.TransactionInstruction
let connection = setupConnection(NETWORKS[network].solana.rpc)
let bridge_id = new web3s.PublicKey(CONTRACTS[network].solana.core)
let token_bridge_id = new web3s.PublicKey(CONTRACTS[network].solana.token_bridge)
let nft_bridge_id = new web3s.PublicKey(CONTRACTS[network].solana.nft_bridge)
let connection = setupConnection(NETWORKS[network][chain].rpc)
let bridge_id = new web3s.PublicKey(CONTRACTS[network][chain].core)
let token_bridge_id = CONTRACTS[network][chain].token_bridge && new web3s.PublicKey(CONTRACTS[network][chain].token_bridge)
let nft_bridge_id = CONTRACTS[network][chain].nft_bridge && new web3s.PublicKey(CONTRACTS[network][chain].nft_bridge)
let from = web3s.Keypair.fromSecretKey(base58.decode(NETWORKS[network].solana.key))
let from = web3s.Keypair.fromSecretKey(base58.decode(NETWORKS[network][chain].key))
switch (v.payload.module) {
case "Core":
if (bridge_id === undefined) {
throw Error("core bridge contract is undefined")
}
const bridge = await importCoreWasm()
switch (v.payload.type) {
case "GuardianSetUpgrade":
@ -36,6 +40,9 @@ export async function execute_solana(
}
break
case "NFTBridge":
if (nft_bridge_id === undefined) {
throw Error("nft bridge contract is undefined")
}
const nft_bridge = await importNftWasm()
switch (v.payload.type) {
case "ContractUpgrade":
@ -54,6 +61,9 @@ export async function execute_solana(
}
break
case "TokenBridge":
if (token_bridge_id === undefined) {
throw Error("token bridge contract is undefined")
}
const token_bridge = await importTokenWasm()
const payload = v.payload;
switch (payload.type) {
@ -67,7 +77,7 @@ export async function execute_solana(
break
case "Transfer":
console.log("Completing transfer")
if (payload.tokenChain === CHAIN_ID_SOLANA) {
if (payload.tokenChain === CHAINS[chain]) {
ix = token_bridge.complete_transfer_native_ix(token_bridge_id.toString(), bridge_id.toString(), from.publicKey.toString(), vaa)
} else {
ix = token_bridge.complete_transfer_wrapped_ix(token_bridge_id.toString(), bridge_id.toString(), from.publicKey.toString(), vaa)