clients/js - initial algorand commit (#1445)
* clients/js - initial algorand commit * clients/js: fix merge issue
This commit is contained in:
parent
cf5c390fc6
commit
639bd3c682
|
@ -0,0 +1,124 @@
|
||||||
|
import { CONTRACTS } from "@certusone/wormhole-sdk";
|
||||||
|
import { NETWORKS } from "./networks";
|
||||||
|
import { impossible, Payload } from "./vaa";
|
||||||
|
import { Account, Algodv2, mnemonicToSecretKey } from "algosdk";
|
||||||
|
import {
|
||||||
|
signSendAndConfirmAlgorand,
|
||||||
|
_submitVAAAlgorand,
|
||||||
|
} from "@certusone/wormhole-sdk/lib/cjs/algorand";
|
||||||
|
|
||||||
|
export async function execute_algorand(
|
||||||
|
payload: Payload,
|
||||||
|
vaa: Uint8Array,
|
||||||
|
environment: "MAINNET" | "TESTNET" | "DEVNET"
|
||||||
|
) {
|
||||||
|
const chainName = "algorand";
|
||||||
|
let n = NETWORKS[environment][chainName];
|
||||||
|
if (!n.key) {
|
||||||
|
throw Error(`No ${environment} key defined for Algorand`);
|
||||||
|
}
|
||||||
|
if (!n.rpc) {
|
||||||
|
throw Error(`No ${environment} rpc defined for Algorand`);
|
||||||
|
}
|
||||||
|
let contracts = CONTRACTS[environment][chainName];
|
||||||
|
console.log("contracts", contracts);
|
||||||
|
const ALGORAND_HOST = {
|
||||||
|
algodToken: "",
|
||||||
|
algodServer: n.rpc,
|
||||||
|
algodPort: "",
|
||||||
|
};
|
||||||
|
if (environment === "DEVNET") {
|
||||||
|
ALGORAND_HOST.algodToken =
|
||||||
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
||||||
|
ALGORAND_HOST.algodPort = "4001";
|
||||||
|
}
|
||||||
|
|
||||||
|
let target_contract: string;
|
||||||
|
|
||||||
|
switch (payload.module) {
|
||||||
|
case "Core":
|
||||||
|
target_contract = contracts.core;
|
||||||
|
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) {
|
||||||
|
// NOTE: this code can safely be removed once the algorand NFT bridge is
|
||||||
|
// released, but it's fine for it to stay, as the condition will just be
|
||||||
|
// skipped once 'contracts.nft_bridge' is defined
|
||||||
|
throw new Error("NFT bridge not supported yet for terra");
|
||||||
|
}
|
||||||
|
target_contract = contracts.nft_bridge;
|
||||||
|
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":
|
||||||
|
if (contracts.token_bridge === undefined) {
|
||||||
|
throw new Error("contracts.token_bridge is undefined");
|
||||||
|
}
|
||||||
|
target_contract = contracts.token_bridge;
|
||||||
|
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:
|
||||||
|
target_contract = impossible(payload);
|
||||||
|
}
|
||||||
|
const target = BigInt(parseInt(target_contract));
|
||||||
|
|
||||||
|
const CORE_ID = BigInt(parseInt(contracts.core));
|
||||||
|
|
||||||
|
const algodClient = new Algodv2(
|
||||||
|
ALGORAND_HOST.algodToken,
|
||||||
|
ALGORAND_HOST.algodServer,
|
||||||
|
ALGORAND_HOST.algodPort
|
||||||
|
);
|
||||||
|
const algoWallet: Account = mnemonicToSecretKey(n.key);
|
||||||
|
|
||||||
|
// Create transaction
|
||||||
|
const txs = await _submitVAAAlgorand(
|
||||||
|
algodClient,
|
||||||
|
target,
|
||||||
|
CORE_ID,
|
||||||
|
vaa,
|
||||||
|
algoWallet.addr
|
||||||
|
);
|
||||||
|
// Sign and send transaction
|
||||||
|
const result = await signSendAndConfirmAlgorand(algodClient, txs, algoWallet);
|
||||||
|
console.log("Confirmed in round:", result["confirmed-round"]);
|
||||||
|
}
|
|
@ -34,6 +34,7 @@ import {
|
||||||
import { ethers } from "ethers";
|
import { ethers } from "ethers";
|
||||||
import { NETWORKS } from "./networks";
|
import { NETWORKS } from "./networks";
|
||||||
import base58 from "bs58";
|
import base58 from "bs58";
|
||||||
|
import { execute_algorand } from "./algorand";
|
||||||
|
|
||||||
setDefaultWasm("node");
|
setDefaultWasm("node");
|
||||||
|
|
||||||
|
@ -609,7 +610,11 @@ yargs(hideBin(process.argv))
|
||||||
} else if (chain === "solana" || chain === "pythnet") {
|
} else if (chain === "solana" || chain === "pythnet") {
|
||||||
await execute_solana(parsed_vaa, buf, network, chain);
|
await execute_solana(parsed_vaa, buf, network, chain);
|
||||||
} else if (chain === "algorand") {
|
} else if (chain === "algorand") {
|
||||||
throw Error("Algorand is not supported yet");
|
await execute_algorand(
|
||||||
|
parsed_vaa.payload,
|
||||||
|
hexToUint8Array(vaa_hex),
|
||||||
|
network
|
||||||
|
);
|
||||||
} else if (chain === "near") {
|
} else if (chain === "near") {
|
||||||
await execute_near(parsed_vaa.payload, vaa_hex, network);
|
await execute_near(parsed_vaa.payload, vaa_hex, network);
|
||||||
} else if (chain === "injective") {
|
} else if (chain === "injective") {
|
||||||
|
|
|
@ -47,8 +47,8 @@ const MAINNET = {
|
||||||
key: get_env_var("ETH_KEY"),
|
key: get_env_var("ETH_KEY"),
|
||||||
},
|
},
|
||||||
algorand: {
|
algorand: {
|
||||||
rpc: undefined,
|
rpc: "https://mainnet-api.algonode.cloud",
|
||||||
key: undefined,
|
key: get_env_var("ALGORAND_KEY"),
|
||||||
},
|
},
|
||||||
oasis: {
|
oasis: {
|
||||||
rpc: "https://emerald.oasis.dev/",
|
rpc: "https://emerald.oasis.dev/",
|
||||||
|
@ -174,8 +174,8 @@ const TESTNET = {
|
||||||
key: get_env_var("ETH_KEY_TESTNET"),
|
key: get_env_var("ETH_KEY_TESTNET"),
|
||||||
},
|
},
|
||||||
algorand: {
|
algorand: {
|
||||||
rpc: undefined,
|
rpc: "https://testnet-api.algonode.cloud",
|
||||||
key: undefined,
|
key: get_env_var("ALGORAND_KEY_TESTNET"),
|
||||||
},
|
},
|
||||||
fantom: {
|
fantom: {
|
||||||
rpc: "https://rpc.testnet.fantom.network",
|
rpc: "https://rpc.testnet.fantom.network",
|
||||||
|
@ -297,8 +297,8 @@ const DEVNET = {
|
||||||
key: "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d",
|
key: "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d",
|
||||||
},
|
},
|
||||||
algorand: {
|
algorand: {
|
||||||
rpc: undefined,
|
rpc: "http://localhost",
|
||||||
key: undefined,
|
key: get_env_var("ALGORAND_KEY_DEVNET"),
|
||||||
},
|
},
|
||||||
fantom: {
|
fantom: {
|
||||||
rpc: undefined,
|
rpc: undefined,
|
||||||
|
@ -338,14 +338,6 @@ const DEVNET = {
|
||||||
rpc: undefined,
|
rpc: undefined,
|
||||||
key: undefined,
|
key: undefined,
|
||||||
},
|
},
|
||||||
aptos: {
|
|
||||||
rpc: undefined,
|
|
||||||
key: undefined,
|
|
||||||
},
|
|
||||||
sui: {
|
|
||||||
rpc: undefined,
|
|
||||||
key: undefined,
|
|
||||||
},
|
|
||||||
pythnet: {
|
pythnet: {
|
||||||
rpc: undefined,
|
rpc: undefined,
|
||||||
key: undefined,
|
key: undefined,
|
||||||
|
@ -354,6 +346,14 @@ const DEVNET = {
|
||||||
rpc: undefined,
|
rpc: undefined,
|
||||||
key: undefined,
|
key: undefined,
|
||||||
},
|
},
|
||||||
|
aptos: {
|
||||||
|
rpc: undefined,
|
||||||
|
key: undefined,
|
||||||
|
},
|
||||||
|
sui: {
|
||||||
|
rpc: undefined,
|
||||||
|
key: undefined,
|
||||||
|
},
|
||||||
moonbeam: {
|
moonbeam: {
|
||||||
rpc: undefined,
|
rpc: undefined,
|
||||||
key: "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d",
|
key: "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d",
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
"@cosmjs/encoding": "^0.26.2",
|
"@cosmjs/encoding": "^0.26.2",
|
||||||
"@solana/web3.js": "^1.22.0",
|
"@solana/web3.js": "^1.22.0",
|
||||||
"@terra-money/terra.js": "^3.1.3",
|
"@terra-money/terra.js": "^3.1.3",
|
||||||
|
"algosdk": "^1.15.0",
|
||||||
"axios": "^0.24.0",
|
"axios": "^0.24.0",
|
||||||
"binary-parser": "^2.0.2",
|
"binary-parser": "^2.0.2",
|
||||||
"bn.js": "^5.2.0",
|
"bn.js": "^5.2.0",
|
||||||
|
@ -2201,9 +2202,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/algosdk": {
|
"node_modules/algosdk": {
|
||||||
"version": "1.17.0",
|
"version": "1.15.0",
|
||||||
"resolved": "https://registry.npmjs.org/algosdk/-/algosdk-1.17.0.tgz",
|
"resolved": "https://registry.npmjs.org/algosdk/-/algosdk-1.15.0.tgz",
|
||||||
"integrity": "sha512-WwHbZV03tZ2C/VLOapWOzJImm4lokav9HXnPLqbGrXyb8Gn/Q2AsoKMbOxd6MTzWguhaXU4Yk0VtbFlYhkaeoA==",
|
"integrity": "sha512-541JhpsmtIh9WcEHBrRsIJhmI8IXsMan0VtCHRfZ1GvWS8CjqafqJUXxDa2kgyZx3wdm/pKin5+gt7HcmfOuaQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"algo-msgpack-with-bigint": "^2.1.1",
|
"algo-msgpack-with-bigint": "^2.1.1",
|
||||||
"buffer": "^6.0.2",
|
"buffer": "^6.0.2",
|
||||||
|
@ -12301,9 +12302,9 @@
|
||||||
"integrity": "sha512-F1tGh056XczEaEAqu7s+hlZUDWwOBT70Eq0lfMpBP2YguSQVyxRbprLq5rELXKQOyOaixTWYhMeMQMzP0U5FoQ=="
|
"integrity": "sha512-F1tGh056XczEaEAqu7s+hlZUDWwOBT70Eq0lfMpBP2YguSQVyxRbprLq5rELXKQOyOaixTWYhMeMQMzP0U5FoQ=="
|
||||||
},
|
},
|
||||||
"algosdk": {
|
"algosdk": {
|
||||||
"version": "1.17.0",
|
"version": "1.15.0",
|
||||||
"resolved": "https://registry.npmjs.org/algosdk/-/algosdk-1.17.0.tgz",
|
"resolved": "https://registry.npmjs.org/algosdk/-/algosdk-1.15.0.tgz",
|
||||||
"integrity": "sha512-WwHbZV03tZ2C/VLOapWOzJImm4lokav9HXnPLqbGrXyb8Gn/Q2AsoKMbOxd6MTzWguhaXU4Yk0VtbFlYhkaeoA==",
|
"integrity": "sha512-541JhpsmtIh9WcEHBrRsIJhmI8IXsMan0VtCHRfZ1GvWS8CjqafqJUXxDa2kgyZx3wdm/pKin5+gt7HcmfOuaQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"algo-msgpack-with-bigint": "^2.1.1",
|
"algo-msgpack-with-bigint": "^2.1.1",
|
||||||
"buffer": "^6.0.2",
|
"buffer": "^6.0.2",
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
"@cosmjs/encoding": "^0.26.2",
|
"@cosmjs/encoding": "^0.26.2",
|
||||||
"@solana/web3.js": "^1.22.0",
|
"@solana/web3.js": "^1.22.0",
|
||||||
"@terra-money/terra.js": "^3.1.3",
|
"@terra-money/terra.js": "^3.1.3",
|
||||||
|
"algosdk": "^1.15.0",
|
||||||
"axios": "^0.24.0",
|
"axios": "^0.24.0",
|
||||||
"binary-parser": "^2.0.2",
|
"binary-parser": "^2.0.2",
|
||||||
"bn.js": "^5.2.0",
|
"bn.js": "^5.2.0",
|
||||||
|
|
Loading…
Reference in New Issue