Skip to content

Commit

Permalink
feat(svm): include solana artifacts in package build output (#806)
Browse files Browse the repository at this point in the history
* feat(svm): add types to dist

Signed-off-by: Pablo Maldonado <[email protected]>

* feat(svm): types

Signed-off-by: Pablo Maldonado <[email protected]>

* fix: ci

Signed-off-by: Pablo Maldonado <[email protected]>

* feat: add getters

Signed-off-by: Pablo Maldonado <[email protected]>

* feat: export only assets

Signed-off-by: Pablo Maldonado <[email protected]>

* fix: missing old import

Signed-off-by: Pablo Maldonado <[email protected]>

* fix: export svm

Signed-off-by: Pablo Maldonado <[email protected]>

* feat: read program id from deployed addresses or pass it as arg

Signed-off-by: Pablo Maldonado <[email protected]>

* refactor: rename generate-evm-assets

Signed-off-by: Pablo Maldonado <[email protected]>

* refactor: dif readme

Signed-off-by: Pablo Maldonado <[email protected]>

* refactor: remove diff readme

Signed-off-by: Pablo Maldonado <[email protected]>

* fix: imports

Signed-off-by: Pablo Maldonado <[email protected]>

---------

Signed-off-by: Pablo Maldonado <[email protected]>
  • Loading branch information
md0x authored Jan 13, 2025
1 parent b5aa2d1 commit e03e0b6
Show file tree
Hide file tree
Showing 29 changed files with 273 additions and 139 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ target
**/*.rs.bk
test-ledger
idls
src/svm/assets
8 changes: 4 additions & 4 deletions deployments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ This is because this `deployments.json` file is used by bots in [`@across-protoc

## Ink mainnet (57073)

| Contract Name | Address |
| ------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| Ink_SpokePool | [0xeF684C38F94F48775959ECf2012D7E864ffb9dd4](https://explorer.inkonchain.com/address/0xeF684C38F94F48775959ECf2012D7E864ffb9dd4) |
| MulticallHandler | [0x924a9f036260DdD5808007E1AA95f08eD08aA569](https://explorer.inkonchain.com/address/0x924a9f036260DdD5808007E1AA95f08eD08aA569) |
| Contract Name | Address |
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| Ink_SpokePool | [0xeF684C38F94F48775959ECf2012D7E864ffb9dd4](https://explorer.inkonchain.com/address/0xeF684C38F94F48775959ECf2012D7E864ffb9dd4) |
| MulticallHandler | [0x924a9f036260DdD5808007E1AA95f08eD08aA569](https://explorer.inkonchain.com/address/0x924a9f036260DdD5808007E1AA95f08eD08aA569) |
5 changes: 5 additions & 0 deletions deployments/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,10 @@
"SpokePool": { "address": "0xeF684C38F94F48775959ECf2012D7E864ffb9dd4", "blockNumber": 1139240 },
"SpokePoolVerifier": { "address": "0xB4A8d45647445EA9FC3E1058096142390683dBC2", "blockNumber": 1152853 },
"MulticallHandler": { "address": "0x924a9f036260DdD5808007E1AA95f08eD08aA569", "blockNumber": 1145284 }
},
"1810017368444177321": {
"SvmSpoke": { "address": "YVMQN27RnCNt23NRxzJPumXRd8iovEfKtzkqyMc5vDt", "blockNumber": 0 },
"MessageTransmitter": { "address": "CCTPmbSD7gX1bxKPAmg77w8oFzNFpaQiQUWD43TKaecd", "blockNumber": 0 },
"TokenMessengerMinter": { "address": "CCTPiPYPc6AsJuwueEnWgSgucamXDZwBd53dQ11YiKX3", "blockNumber": 0 }
}
}
2 changes: 1 addition & 1 deletion deployments/ink/SpokePoolVerifier.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@
"storage": [],
"types": null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@
"storageLayout",
"evm.gasEstimates"
],
"": [
"ast"
]
"": ["ast"]
}
},
"metadata": {
"useLiteralContent": true
}
}
}
}
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./typechain";
export * from "./src/DeploymentUtils";
export * from "./utils";
export * from "./src/svm";
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@
"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",
"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/",
"build": "yarn build-evm && yarn build-svm && yarn build-ts",
"build": "yarn build-evm && yarn build-svm && yarn generate-svm-assets && yarn build-ts",
"test-evm": "IS_TEST=true hardhat test",
"test-svm": "anchor test -- --features test",
"test": "yarn test-evm && yarn test-svm",
"test:report-gas": "IS_TEST=true REPORT_GAS=true hardhat test",
"generate-contract-types": "rm -rf typechain && TYPECHAIN=ethers yarn hardhat typechain",
"prepublish": "yarn build && hardhat export --export-all ./cache/massExport.json && ts-node ./scripts/processHardhatExport.ts && prettier --write ./deployments/deployments.json && yarn generate-contract-types",
"generate-evm-assets": "rm -rf typechain && TYPECHAIN=ethers yarn hardhat typechain",
"prepublish": "yarn build && hardhat export --export-all ./cache/massExport.json && ts-node ./scripts/processHardhatExport.ts && prettier --write ./deployments/deployments.json && yarn generate-evm-assets",
"pre-commit-hook": "sh scripts/preCommitHook.sh"
},
"dependencies": {
Expand Down
89 changes: 89 additions & 0 deletions scripts/generate-svm-assets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash

# Set paths for source and destination
TARGET_IDL="./target/idl"
TARGET_TYPES="./target/types"
SVM_ASSETS="./src/svm/assets"
SVM_IDL="$SVM_ASSETS/idl"
SVM_TYPES="$SVM_ASSETS"
IDL_OUTPUT_FILE="$SVM_IDL/index.ts"
TYPES_OUTPUT_FILE="$SVM_TYPES/index.ts"

# Ensure the destination directories exist
mkdir -p "$SVM_IDL"
mkdir -p "$SVM_TYPES"

# --- Copy Files ---
echo "Copying IDL files..."
cp -r "$TARGET_IDL/"* "$SVM_IDL/"

echo "Copying Types files..."
cp -r "$TARGET_TYPES/"* "$SVM_TYPES/"

# --- Generate IDL index.ts ---
echo "Generating IDL index.ts..."
> "$IDL_OUTPUT_FILE"

# Add autogenerated file note
{
echo "// This file has been autogenerated. Do not edit manually."
echo "// Generated by a script."
echo
} >> "$IDL_OUTPUT_FILE"

IMPORTS=""
EXPORTS=""

for file in "$SVM_IDL"/*.json; do
filename=$(basename -- "$file")
name="${filename%.json}"
camelCaseName=$(echo "$name" | awk -F'_' '{
for (i=1; i<=NF; i++) {
printf toupper(substr($i,1,1)) tolower(substr($i,2));
}
}')
IMPORTS="${IMPORTS}const ${camelCaseName}Idl = require(\"./${filename}\");\n"
EXPORTS="${EXPORTS} ${camelCaseName}Idl,\n"
done

# Write the imports to the file
printf "$IMPORTS" >> "$IDL_OUTPUT_FILE"

# Write the exports block
{
echo "export {"
printf "$EXPORTS" | sed '$ s/,$//'
echo "};"
} >> "$IDL_OUTPUT_FILE"

echo "IDL index.ts generated successfully at $IDL_OUTPUT_FILE"

# --- Generate svm-types index.ts ---
echo "Generating svm-types index.ts..."
> "$TYPES_OUTPUT_FILE"

# Add autogenerated file note
{
echo "// This file has been autogenerated. Do not edit manually."
echo "// Generated by a script."
echo
} >> "$TYPES_OUTPUT_FILE"

# Export * from ./idl
echo "export * from \"./idl\";" >> "$TYPES_OUTPUT_FILE"

# Export * from each .ts file in ./svm-types, removing underscores and capitalizing names
for file in "$SVM_TYPES"/*.ts; do
[ "$(basename -- "$file")" = "index.ts" ] && continue
filename=$(basename -- "$file")
name="${filename%.ts}"
camelCaseName=$(echo "$name" | awk -F'_' '{
for (i=1; i<=NF; i++) {
printf toupper(substr($i,1,1)) tolower(substr($i,2));
}
}')
newName="${camelCaseName}Anchor"
echo "export {${camelCaseName} as ${newName}} from \"./${name}\";" >> "$TYPES_OUTPUT_FILE"
done

echo "svm-types index.ts generated successfully at $TYPES_OUTPUT_FILE"
16 changes: 5 additions & 11 deletions scripts/svm/bridgeLiabilityToHubPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@
*/

import * as anchor from "@coral-xyz/anchor";
import { AnchorProvider, BN, Program } from "@coral-xyz/anchor";
import { AnchorProvider, BN } from "@coral-xyz/anchor";
import { ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { PublicKey, SystemProgram } from "@solana/web3.js";
// eslint-disable-next-line camelcase
import { MessageTransmitter } from "../../target/types/message_transmitter";
import { SvmSpoke } from "../../target/types/svm_spoke";
// eslint-disable-next-line camelcase
import {
CIRCLE_IRIS_API_URL_DEVNET,
CIRCLE_IRIS_API_URL_MAINNET,
Expand All @@ -46,7 +43,7 @@ import {
import { TOKEN_SYMBOLS_MAP } from "@across-protocol/constants";
import { getNodeUrl } from "@uma/common";
import { BigNumber, ethers } from "ethers";
import { TokenMessengerMinter } from "../../target/types/token_messenger_minter";
import { getMessageTransmitterProgram, getSpokePoolProgram, getTokenMessengerMinterProgram } from "../../src/svm";
import { BondToken__factory } from "../../typechain";
import { formatUsdc, requireEnv } from "./utils/helpers";

Expand All @@ -55,10 +52,7 @@ const provider = AnchorProvider.env();
anchor.setProvider(provider);

// Get Solana programs and IDLs.
const svmSpokeIdl = require("../../target/idl/svm_spoke.json");
const svmSpokeProgram = new Program<SvmSpoke>(svmSpokeIdl, provider);
const messageTransmitterIdl = require("../../target/idl/message_transmitter.json");
const tokenMessengerMinterIdl = require("../../target/idl/token_messenger_minter.json");
const svmSpokeProgram = getSpokePoolProgram(provider);

// CCTP domains.
const ethereumDomain = 0; // Ethereum
Expand Down Expand Up @@ -200,7 +194,7 @@ async function bridgeLiabilityToHubPool(): Promise<void> {
}

async function bridgeTokensToHubPool(amount: BN, signer: anchor.Wallet, statePda: PublicKey, inputToken: PublicKey) {
const messageTransmitterProgram = new Program<MessageTransmitter>(messageTransmitterIdl, provider);
const messageTransmitterProgram = getMessageTransmitterProgram(provider);

const vault = getAssociatedTokenAddressSync(
inputToken,
Expand All @@ -215,7 +209,7 @@ async function bridgeTokensToHubPool(amount: BN, signer: anchor.Wallet, statePda
[Buffer.from("transfer_liability"), inputToken.toBuffer()],
svmSpokeProgram.programId
);
const tokenMessengerMinterProgram = new Program<TokenMessengerMinter>(tokenMessengerMinterIdl, provider);
const tokenMessengerMinterProgram = getTokenMessengerMinterProgram(provider);

const [tokenMessengerMinterSenderAuthority] = PublicKey.findProgramAddressSync(
[Buffer.from("sender_authority")],
Expand Down
8 changes: 3 additions & 5 deletions scripts/svm/closeRelayerPdas.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// This script closes all Relayer PDAs associated with tracking fill Status. Relayers should do this periodically to
// reclaim the lamports within these tracking accounts. Fill Status PDAs can be closed on the deposit has expired.
import * as anchor from "@coral-xyz/anchor";
import { BN, Program, AnchorProvider } from "@coral-xyz/anchor";
import { AnchorProvider, BN } from "@coral-xyz/anchor";
import { PublicKey, SystemProgram } from "@solana/web3.js";
import { SvmSpoke } from "../../target/types/svm_spoke";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { calculateRelayEventHashUint8Array, readProgramEvents } from "../../src/svm";
import { calculateRelayEventHashUint8Array, getSpokePoolProgram, readProgramEvents } from "../../src/svm";

// Set up the provider
const provider = AnchorProvider.env();
anchor.setProvider(provider);
const idl = require("../../target/idl/svm_spoke.json");
const program = new Program<SvmSpoke>(idl, provider);
const program = getSpokePoolProgram(provider);
const programId = program.programId;

// Parse arguments
Expand Down
9 changes: 4 additions & 5 deletions scripts/svm/enableRoute.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// This script is used by a chain admin to enable or disable a route for a token on the Solana Spoke Pool.

import * as anchor from "@coral-xyz/anchor";
import { BN, Program, AnchorProvider } from "@coral-xyz/anchor";
import { PublicKey, SystemProgram } from "@solana/web3.js";
import { AnchorProvider, BN } from "@coral-xyz/anchor";
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from "@solana/spl-token";
import { SvmSpoke } from "../../target/types/svm_spoke";
import { PublicKey, SystemProgram } from "@solana/web3.js";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { getSpokePoolProgram } from "../../src/svm";

// Set up the provider
const provider = AnchorProvider.env();
anchor.setProvider(provider);
const idl = require("../../target/idl/svm_spoke.json");
const program = new Program<SvmSpoke>(idl, provider);
const program = getSpokePoolProgram(provider);
const programId = program.programId;
console.log("SVM-Spoke Program ID:", programId.toString());

Expand Down
14 changes: 7 additions & 7 deletions scripts/svm/executeRebalanceToHubPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ import {
import { BigNumber, ethers } from "ethers";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { MessageTransmitter } from "../../target/types/message_transmitter";
import { SvmSpoke } from "../../target/types/svm_spoke";
import { CHAIN_IDs } from "../../utils/constants";
// eslint-disable-next-line camelcase
import { HubPool__factory } from "../../typechain";
Expand All @@ -61,12 +59,15 @@ import {
CIRCLE_IRIS_API_URL_MAINNET,
decodeMessageHeader,
getMessages,
getMessageTransmitterProgram,
getSolanaChainId,
getSpokePoolProgram,
isSolanaDevnet,
loadExecuteRelayerRefundLeafParams,
SOLANA_SPOKE_STATE_SEED,
SOLANA_USDC_DEVNET,
SOLANA_USDC_MAINNET,
SvmSpokeAnchor,
} from "../../src/svm";
import { RelayerRefundLeafSolana, RelayerRefundLeafType } from "../../src/types/svm";

Expand All @@ -75,10 +76,9 @@ const provider = AnchorProvider.env();
anchor.setProvider(provider);

// Get Solana programs.
const svmSpokeIdl = require("../../target/idl/svm_spoke.json");
const svmSpokeProgram = new Program<SvmSpoke>(svmSpokeIdl, provider);
const messageTransmitterIdl = require("../../target/idl/message_transmitter.json");
const messageTransmitterProgram = new Program<MessageTransmitter>(messageTransmitterIdl, provider);

const svmSpokeProgram = getSpokePoolProgram(provider);
const messageTransmitterProgram = getMessageTransmitterProgram(provider);

const [messageTransmitterState] = PublicKey.findProgramAddressSync(
[Buffer.from("message_transmitter")],
Expand Down Expand Up @@ -340,7 +340,7 @@ async function executeRootBalanceOnHubPool(solanaChainId: BigNumber) {

async function executeRelayerRefundLeaf(
signer: anchor.Wallet,
program: Program<SvmSpoke>,
program: Program<SvmSpokeAnchor>,
statePda: PublicKey,
rootBundle: PublicKey,
relayerRefundLeaf: RelayerRefundLeafSolana,
Expand Down
26 changes: 11 additions & 15 deletions scripts/svm/executeRebalanceToSpokePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
// - HUB_POOL_ADDRESS: Hub Pool address

import * as anchor from "@coral-xyz/anchor";
import { BN, Program, AnchorProvider } from "@coral-xyz/anchor";
import { AnchorProvider, BN } from "@coral-xyz/anchor";
import { getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { AccountMeta, PublicKey, SystemProgram } from "@solana/web3.js";
import { TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from "@solana/spl-token";
import { getNodeUrl } from "@uma/common";
// eslint-disable-next-line camelcase
import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "../../utils/constants";
import { SvmSpoke } from "../../target/types/svm_spoke";
import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "@across-protocol/constants";
import { BigNumber, ethers } from "ethers";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import {
Expand All @@ -19,30 +19,26 @@ import {
decodeMessageHeader,
evmAddressToPublicKey,
getMessages,
getMessageTransmitterProgram,
getSolanaChainId,
getSpokePoolProgram,
getTokenMessengerMinterProgram,
isSolanaDevnet,
SOLANA_USDC_DEVNET,
SOLANA_USDC_MAINNET,
} from "../../src/svm";
import { MessageTransmitter } from "../../target/types/message_transmitter";
import { TokenMessengerMinter } from "../../target/types/token_messenger_minter";
import { ethers, BigNumber } from "ethers";
// eslint-disable-next-line camelcase
import { HubPool__factory } from "../../typechain";
import { constructSimpleRebalanceTree } from "./utils/poolRebalanceTree";
import { requireEnv } from "./utils/helpers";
import { constructSimpleRebalanceTree } from "./utils/poolRebalanceTree";

// Set up Solana provider.
const provider = AnchorProvider.env();
anchor.setProvider(provider);

// Get Solana programs.
const svmSpokeIdl = require("../../target/idl/svm_spoke.json");
const svmSpokeProgram = new Program<SvmSpoke>(svmSpokeIdl, provider);
const messageTransmitterIdl = require("../../target/idl/message_transmitter.json");
const messageTransmitterProgram = new Program<MessageTransmitter>(messageTransmitterIdl, provider);
const tokenMessengerMinterIdl = require("../../target/idl/token_messenger_minter.json");
const tokenMessengerMinterProgram = new Program<TokenMessengerMinter>(tokenMessengerMinterIdl, provider);
const svmSpokeProgram = getSpokePoolProgram(provider);
const messageTransmitterProgram = getMessageTransmitterProgram(provider);
const tokenMessengerMinterProgram = getTokenMessengerMinterProgram(provider);

// Set up Ethereum provider and signer.
const isDevnet = isSolanaDevnet(provider);
Expand Down
Loading

0 comments on commit e03e0b6

Please sign in to comment.