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(svm): web3 v2, codama clients, and events retrieval #866

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ target
**/*.rs.bk
test-ledger
src/svm/assets
src/svm/clients/*
!src/svm/clients/index.ts
1 change: 1 addition & 0 deletions Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ wallet = "test/svm/keys/localnet-wallet.json"
[scripts]
test = "anchor run generateExternalTypes && yarn run ts-mocha -p ./tsconfig.json -t 1000000 test/svm/**/*.ts"
queryEvents = "NODE_NO_WARNINGS=1 yarn run ts-node ./scripts/svm/queryEvents.ts"
queryEventsV2 = "NODE_NO_WARNINGS=1 yarn run ts-node ./scripts/svm/queryEventsV2.ts"
initialize = "NODE_NO_WARNINGS=1 yarn run ts-node ./scripts/svm/initialize.ts"
queryState = "NODE_NO_WARNINGS=1 yarn run ts-node ./scripts/svm/queryState.ts"
enableRoute = "NODE_NO_WARNINGS=1 yarn run ts-node ./scripts/svm/enableRoute.ts"
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@across-protocol/contracts",
"version": "3.0.25",
"version": "3.0.26",
"author": "UMA Team",
"license": "AGPL-3.0-only",
"repository": {
Expand All @@ -26,7 +26,8 @@
"lint-fix": "yarn prettier --write **/*.js **/*.ts ./programs/**/*.rs ./contracts**/*.sol && cargo +nightly fmt --all && cargo clippy",
"clean-fast": "for dir in node_modules cache cache-zk artifacts artifacts-zk dist typechain; do mv \"${dir}\" \"_${dir}\"; rm -rf \"_${dir}\" &; done",
"clean": "rm -rf node_modules cache cache-zk artifacts artifacts-zk dist typechain",
"generate-svm-assets": "sh ./scripts/generate-svm-assets.sh",
"generate-svm-assets": "sh ./scripts/generate-svm-assets.sh && yarn generate-svm-clients",
"generate-svm-clients": "yarn ts-node ./scripts/svm/utils/generate-svm-clients.ts && yarn ts-node ./scripts/svm/utils/rename-clients-imports.ts",
"build-evm": "hardhat compile",
"build-svm": "echo 'Generating IDLs...' && anchor build > /dev/null 2>&1 || true && anchor run generateExternalTypes && anchor build",
"build-ts": "tsc && rsync -a --include '*/' --include '*.d.ts' --exclude '*' ./typechain ./dist/",
Expand Down Expand Up @@ -54,6 +55,7 @@
"@solana-developers/helpers": "^2.4.0",
"@solana/spl-token": "^0.4.6",
"@solana/web3.js": "^1.31.0",
"@solana/web3-v2.js": "npm:@solana/web3.js@2",
"@types/yargs": "^17.0.33",
"@uma/common": "^2.37.3",
"@uma/contracts-node": "^0.4.17",
Expand All @@ -65,6 +67,9 @@
"zksync-web3": "^0.14.3"
},
"devDependencies": {
"@codama/nodes-from-anchor": "^1.1.0",
"@codama/renderers-js": "^1.1.1",
"codama": "^1.2.0",
"@consensys/linea-sdk": "^0.1.6",
"@matterlabs/hardhat-zksync-deploy": "^0.6.3",
"@matterlabs/hardhat-zksync-solc": "^1.1.4",
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/addressToPublicKey.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { evmAddressToPublicKey } from "../../src/svm";
import { evmAddressToPublicKey } from "../../src/svm/web3-v1";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
const argv = yargs(hideBin(process.argv)).option("address", {
Expand Down
8 changes: 6 additions & 2 deletions scripts/svm/bridgeLiabilityToHubPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ import {
SOLANA_SPOKE_STATE_SEED,
SOLANA_USDC_DEVNET,
SOLANA_USDC_MAINNET,
} from "../../src/svm";
} from "../../src/svm/web3-v1";

import { TOKEN_SYMBOLS_MAP } from "@across-protocol/constants";
import { getNodeUrl } from "@uma/common";
import { BigNumber, ethers } from "ethers";
import { getMessageTransmitterProgram, getSpokePoolProgram, getTokenMessengerMinterProgram } from "../../src/svm";
import {
getMessageTransmitterProgram,
getSpokePoolProgram,
getTokenMessengerMinterProgram,
} from "../../src/svm/web3-v1";
import { BondToken__factory } from "../../typechain";
import { formatUsdc, requireEnv } from "./utils/helpers";

Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/closeRelayerPdas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AnchorProvider, BN } from "@coral-xyz/anchor";
import { PublicKey, SystemProgram } from "@solana/web3.js";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { calculateRelayEventHashUint8Array, getSpokePoolProgram, readProgramEvents } from "../../src/svm";
import { calculateRelayEventHashUint8Array, getSpokePoolProgram, readProgramEvents } from "../../src/svm/web3-v1";

// Set up the provider
const provider = AnchorProvider.env();
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/enableRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getAssociatedTokenAddres
import { PublicKey, SystemProgram } from "@solana/web3.js";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { getSpokePoolProgram } from "../../src/svm";
import { getSpokePoolProgram } from "../../src/svm/web3-v1";

// Set up the provider
const provider = AnchorProvider.env();
Expand Down
4 changes: 2 additions & 2 deletions scripts/svm/executeRebalanceToHubPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ import {
SOLANA_SPOKE_STATE_SEED,
SOLANA_USDC_DEVNET,
SOLANA_USDC_MAINNET,
SvmSpokeAnchor,
} from "../../src/svm";
} from "../../src/svm/web3-v1";
import { RelayerRefundLeafSolana, RelayerRefundLeafType } from "../../src/types/svm";
import { SvmSpokeAnchor } from "../../src/svm";

// Set up Solana provider.
const provider = AnchorProvider.env();
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/executeRebalanceToSpokePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
isSolanaDevnet,
SOLANA_USDC_DEVNET,
SOLANA_USDC_MAINNET,
} from "../../src/svm";
} from "../../src/svm/web3-v1";
import { HubPool__factory } from "../../typechain";
import { requireEnv } from "./utils/helpers";
import { constructSimpleRebalanceTree } from "./utils/poolRebalanceTree";
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/fakeFillWithRandomDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
getSpokePoolProgram,
loadFillV3RelayParams,
sendTransactionWithLookupTable,
} from "../../src/svm";
} from "../../src/svm/web3-v1";
import { FillDataParams, FillDataValues } from "../../src/types/svm";

// Set up the provider and signer.
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AnchorProvider, BN } from "@coral-xyz/anchor";
import { PublicKey, SystemProgram } from "@solana/web3.js";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { evmAddressToPublicKey, getSpokePoolProgram } from "../../src/svm";
import { evmAddressToPublicKey, getSpokePoolProgram } from "../../src/svm/web3-v1";

// Set up the provider
const provider = AnchorProvider.env();
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/proposeRebalanceToHubPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { getNodeUrl } from "@uma/common";
import { BigNumber, ethers } from "ethers";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { getSolanaChainId, SOLANA_USDC_DEVNET, SOLANA_USDC_MAINNET } from "../../src/svm";
import { getSolanaChainId, SOLANA_USDC_DEVNET, SOLANA_USDC_MAINNET } from "../../src/svm/web3-v1";
import { BondToken__factory, HubPool__factory } from "../../typechain";
import { CHAIN_IDs } from "../../utils/constants";
import {
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/proposeRebalanceToSpokePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "../../utils/constants";
// eslint-disable-next-line camelcase
import { getSolanaChainId } from "../../src/svm";
import { getSolanaChainId } from "../../src/svm/web3-v1";
import { BondToken__factory, HubPool__factory } from "../../typechain";
import { requireEnv } from "./utils/helpers";
import { constructSimpleRebalanceTree } from "./utils/poolRebalanceTree";
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/publicKeyToAddress.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { publicKeyToEvmAddress } from "../../src/svm";
import { publicKeyToEvmAddress } from "../../src/svm/web3-v1";

const argv = yargs(hideBin(process.argv)).option("publicKey", {
type: "string",
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/queryDeposits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AnchorProvider, BN } from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { getSpokePoolProgram, readProgramEvents } from "../../src/svm";
import { getSpokePoolProgram, readProgramEvents } from "../../src/svm/web3-v1";

// Set up the provider
const provider = AnchorProvider.env();
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/queryEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as anchor from "@coral-xyz/anchor";
import { AnchorProvider, Program } from "@coral-xyz/anchor";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { readProgramEvents, stringifyCpiEvent } from "../../src/svm";
import { readProgramEvents, stringifyCpiEvent } from "../../src/svm/web3-v1";
import { SvmSpoke } from "../../target/types/svm_spoke";

// Set up the provider
Expand Down
54 changes: 54 additions & 0 deletions scripts/svm/queryEventsV2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// This script queries the events of the spoke pool and prints them in a human readable format.
import { AnchorProvider } from "@coral-xyz/anchor";
import { address, createSolanaRpc } from "@solana/web3-v2.js";
import { stringifyCpiEvent } from "../../src/svm/web3-v1";
import { SvmSpokeIdl } from "../../src/svm";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { readProgramEvents } from "../../src/svm";

// Set up the provider
const provider = AnchorProvider.env();

const argvPromise = yargs(hideBin(process.argv))
.option("eventName", {
type: "string",
demandOption: false,
describe: "Name of the event to query",
choices: [
"any",
"FilledV3Relay",
"V3FundsDeposited",
"EnabledDepositRoute",
"RelayedRootBundle",
"ExecutedRelayerRefundRoot",
"BridgedToHubPool",
"PausedDeposits",
"PausedFills",
"SetXDomainAdmin",
"EmergencyDeletedRootBundle",
"RequestedV3SlowFill",
"ClaimedRelayerRefund",
"TokensBridged",
],
})
.option("programId", {
type: "string",
demandOption: true,
describe: "SvmSpokeProgram ID to query events from",
}).argv;

async function queryEvents(): Promise<void> {
const argv = await argvPromise;
const eventName = argv.eventName || "any";
const programId = argv.programId;
const rpc = createSolanaRpc(provider.connection.rpcEndpoint);
const events = await readProgramEvents(rpc, address(programId), SvmSpokeIdl, "confirmed");
const filteredEvents = events.filter((event: any) => (eventName == "any" ? true : event.name == eventName));
const formattedEvents = filteredEvents.map((event: any) => stringifyCpiEvent(event));

console.log(JSON.stringify(formattedEvents, null, 2));
}

// Run the queryEvents function
queryEvents();
2 changes: 1 addition & 1 deletion scripts/svm/queryFills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AnchorProvider, BN } from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { getSpokePoolProgram, readProgramEvents, strPublicKey, u8Array32ToInt } from "../../src/svm";
import { getSpokePoolProgram, readProgramEvents, strPublicKey, u8Array32ToInt } from "../../src/svm/web3-v1";

// Set up the provider
const provider = AnchorProvider.env();
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/queryRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { PublicKey } from "@solana/web3.js";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { getSpokePoolProgram } from "../../src/svm";
import { getSpokePoolProgram } from "../../src/svm/web3-v1";

// Set up the provider
const provider = AnchorProvider.env();
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/queryState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AnchorProvider, BN } from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { getSpokePoolProgram } from "../../src/svm";
import { getSpokePoolProgram } from "../../src/svm/web3-v1";

// Set up the provider
const provider = AnchorProvider.env();
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/remoteHubPoolPauseDeposits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
getMessageTransmitterProgram,
getSpokePoolProgram,
isSolanaDevnet,
} from "../../src/svm";
} from "../../src/svm/web3-v1";
import { HubPool__factory } from "../../typechain";
import { requireEnv } from "./utils/helpers";

Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/remoteHubPoolSetDepositRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
isSolanaDevnet,
SOLANA_USDC_DEVNET,
SOLANA_USDC_MAINNET,
} from "../../src/svm";
} from "../../src/svm/web3-v1";
import { HubPool__factory } from "../../typechain";
import { CHAIN_IDs } from "../../utils/constants";
import { requireEnv } from "./utils/helpers";
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/remotePauseDeposits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
isSolanaDevnet,
MAINNET_CCTP_MESSAGE_TRANSMITTER_ADDRESS,
SEPOLIA_CCTP_MESSAGE_TRANSMITTER_ADDRESS,
} from "../../src/svm";
} from "../../src/svm/web3-v1";
import { CHAIN_IDs } from "../../utils/constants";
import { requireEnv } from "./utils/helpers";

Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/simpleDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { PublicKey, Transaction, sendAndConfirmTransaction } from "@solana/web3.js";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { getSpokePoolProgram } from "../../src/svm";
import { getSpokePoolProgram } from "../../src/svm/web3-v1";

// Set up the provider
const provider = AnchorProvider.env();
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/simpleFakeRelayerRepayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import { MerkleTree } from "@uma/common/dist/MerkleTree";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { getSpokePoolProgram, loadExecuteRelayerRefundLeafParams, relayerRefundHashFn } from "../../src/svm";
import { getSpokePoolProgram, loadExecuteRelayerRefundLeafParams, relayerRefundHashFn } from "../../src/svm/web3-v1";
import { RelayerRefundLeafSolana, RelayerRefundLeafType } from "../../src/types/svm";

// Set up the provider
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/simpleFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { PublicKey, SystemProgram, Transaction, sendAndConfirmTransaction } from "@solana/web3.js";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { calculateRelayHashUint8Array, getSpokePoolProgram, intToU8Array32 } from "../../src/svm";
import { calculateRelayHashUint8Array, getSpokePoolProgram, intToU8Array32 } from "../../src/svm/web3-v1";

// Set up the provider
const provider = AnchorProvider.env();
Expand Down
24 changes: 24 additions & 0 deletions scripts/svm/utils/generate-svm-clients.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createFromRoot } from "codama";
import { rootNodeFromAnchor, AnchorIdl } from "@codama/nodes-from-anchor";
import { renderVisitor as renderJavaScriptVisitor } from "@codama/renderers-js";
import { SvmSpokeIdl, MulticallHandlerIdl } from "../../../src/svm/assets";
import path from "path";
export const clientsPath = path.join(__dirname, "..", "..", "..", "src", "svm", "clients");

// Generate SvmSpoke clients
let codama = createFromRoot(rootNodeFromAnchor(SvmSpokeIdl as AnchorIdl));
codama.accept(renderJavaScriptVisitor(path.join(clientsPath, "SvmSpoke")));

// Generate MulticallHandler clients
codama = createFromRoot(rootNodeFromAnchor(MulticallHandlerIdl as AnchorIdl));
codama.accept(renderJavaScriptVisitor(path.join(clientsPath, "MulticallHandler")));

// codama = createFromRoot(rootNodeFromAnchor(MessageTransmitterIdl as AnchorIdl));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending to fix.

// codama.accept(
// renderJavaScriptVisitor(path.join(clientsPath, "MessageTransmitter"))
// );

// codama = createFromRoot(rootNodeFromAnchor(TokenMessengerMinterIdl as AnchorIdl));
// codama.accept(
// renderJavaScriptVisitor(path.join(clientsPath, "TokenMessengerMinter"))
// );
2 changes: 1 addition & 1 deletion scripts/svm/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BN } from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";
import { MerkleTree } from "@uma/common";
import { BigNumber, ethers } from "ethers";
import { relayerRefundHashFn } from "../../../src/svm";
import { relayerRefundHashFn } from "../../../src/svm/web3-v1";
import { RelayerRefundLeafSolana, RelayerRefundLeafType } from "../../../src/types/svm";

export const requireEnv = (name: string): string => {
Expand Down
22 changes: 22 additions & 0 deletions scripts/svm/utils/rename-clients-imports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const fs = require("fs");
const path = require("path");

const clientsPath = path.join(__dirname, "..", "..", "..", "src", "svm", "clients");

function replaceInFiles(dir: string): void {
const files = fs.readdirSync(dir);
files.forEach((file: string) => {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);

if (stat.isDirectory()) {
replaceInFiles(filePath);
} else if (file.endsWith(".ts")) {
const fileContent = fs.readFileSync(filePath, "utf8");
const updatedContent = fileContent.replace("@solana/web3.js", "@solana/web3-v2.js");
fs.writeFileSync(filePath, updatedContent);
}
});
}

replaceInFiles(clientsPath);
4 changes: 4 additions & 0 deletions src/svm/clients/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as MulticallHandlerClient from "./MulticallHandler";
import * as SvmSpokeClient from "./SvmSpoke";

export { MulticallHandlerClient, SvmSpokeClient };
12 changes: 2 additions & 10 deletions src/svm/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
export * from "./relayHashUtils";
export * from "./instructionParamsUtils";
export * from "./conversionUtils";
export * from "./transactionUtils";
export * from "./solanaProgramUtils";
export * from "./coders";
export * from "./programConnectors";
export * from "./web3-v2";
export * from "./assets";
export * from "./constants";
export * from "./helpers";
export * from "./cctpHelpers";
export * from "./clients";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as anchor from "@coral-xyz/anchor";
import { array, object, optional, string, Struct } from "superstruct";
import { readUInt256BE } from "../../src/svm";
import { readUInt256BE } from "./relayHashUtils";

// Index positions to decode Message Header from
// https://developers.circle.com/stablecoins/docs/message-format#message-header
Expand Down
Loading
Loading