Skip to content

Commit

Permalink
feat(svm): add codama clients
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Maldonado <[email protected]>
  • Loading branch information
md0x committed Jan 16, 2025
1 parent 580ef11 commit ebc0a98
Show file tree
Hide file tree
Showing 7 changed files with 688 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ target
test-ledger
idls
src/svm/assets
src/svm/clients/*
!src/svm/clients/index.ts
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions scripts/svm/utils/generate-svm-clients.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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";

let codama = createFromRoot(rootNodeFromAnchor(SvmSpokeIdl as AnchorIdl));
export const clientsPath = path.join(__dirname, "..", "..", "..", "src", "svm", "clients");

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

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

// codama = createFromRoot(rootNodeFromAnchor(MessageTransmitterIdl as AnchorIdl));
// codama.accept(
// renderJavaScriptVisitor(path.join(clientsPath, "MessageTransmitter"))
// );

// codama = createFromRoot(rootNodeFromAnchor(TokenMessengerMinterIdl as AnchorIdl));
// codama.accept(
// renderJavaScriptVisitor(path.join(clientsPath, "TokenMessengerMinter"))
// );
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 @@
import { clientsPath } from "./generate-svm-clients";

const fs = require("fs");
const path = require("path");

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);
2 changes: 2 additions & 0 deletions src/svm/clients/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./MulticallHandler";
export * from "./SvmSpoke";
1 change: 1 addition & 0 deletions src/svm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from "./assets";
export * from "./constants";
export * from "./helpers";
export * from "./cctpHelpers";
export * from "./clients";
Loading

0 comments on commit ebc0a98

Please sign in to comment.