Skip to content

Commit e03e0b6

Browse files
authored
feat(svm): include solana artifacts in package build output (#806)
* 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]>
1 parent b5aa2d1 commit e03e0b6

29 files changed

+273
-139
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ target
3232
**/*.rs.bk
3333
test-ledger
3434
idls
35+
src/svm/assets

deployments/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ This is because this `deployments.json` file is used by bots in [`@across-protoc
133133

134134
## Ink mainnet (57073)
135135

136-
| Contract Name | Address |
137-
| ------------- | -------------------------------------------------------------------------------------------------------------------------------- |
138-
| Ink_SpokePool | [0xeF684C38F94F48775959ECf2012D7E864ffb9dd4](https://explorer.inkonchain.com/address/0xeF684C38F94F48775959ECf2012D7E864ffb9dd4) |
139-
| MulticallHandler | [0x924a9f036260DdD5808007E1AA95f08eD08aA569](https://explorer.inkonchain.com/address/0x924a9f036260DdD5808007E1AA95f08eD08aA569) |
136+
| Contract Name | Address |
137+
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------- |
138+
| Ink_SpokePool | [0xeF684C38F94F48775959ECf2012D7E864ffb9dd4](https://explorer.inkonchain.com/address/0xeF684C38F94F48775959ECf2012D7E864ffb9dd4) |
139+
| MulticallHandler | [0x924a9f036260DdD5808007E1AA95f08eD08aA569](https://explorer.inkonchain.com/address/0x924a9f036260DdD5808007E1AA95f08eD08aA569) |

deployments/deployments.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,10 @@
168168
"SpokePool": { "address": "0xeF684C38F94F48775959ECf2012D7E864ffb9dd4", "blockNumber": 1139240 },
169169
"SpokePoolVerifier": { "address": "0xB4A8d45647445EA9FC3E1058096142390683dBC2", "blockNumber": 1152853 },
170170
"MulticallHandler": { "address": "0x924a9f036260DdD5808007E1AA95f08eD08aA569", "blockNumber": 1145284 }
171+
},
172+
"1810017368444177321": {
173+
"SvmSpoke": { "address": "YVMQN27RnCNt23NRxzJPumXRd8iovEfKtzkqyMc5vDt", "blockNumber": 0 },
174+
"MessageTransmitter": { "address": "CCTPmbSD7gX1bxKPAmg77w8oFzNFpaQiQUWD43TKaecd", "blockNumber": 0 },
175+
"TokenMessengerMinter": { "address": "CCTPiPYPc6AsJuwueEnWgSgucamXDZwBd53dQ11YiKX3", "blockNumber": 0 }
171176
}
172177
}

deployments/ink/SpokePoolVerifier.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,4 @@
112112
"storage": [],
113113
"types": null
114114
}
115-
}
115+
}

deployments/ink/solcInputs/53ab13385da43753d9a657e7780a0560.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@
3333
"storageLayout",
3434
"evm.gasEstimates"
3535
],
36-
"": [
37-
"ast"
38-
]
36+
"": ["ast"]
3937
}
4038
},
4139
"metadata": {
4240
"useLiteralContent": true
4341
}
4442
}
45-
}
43+
}

index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./typechain";
22
export * from "./src/DeploymentUtils";
33
export * from "./utils";
4+
export * from "./src/svm";

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@
2626
"lint-fix": "yarn prettier --write **/*.js **/*.ts ./programs/**/*.rs ./contracts**/*.sol && cargo +nightly fmt --all && cargo clippy",
2727
"clean-fast": "for dir in node_modules cache cache-zk artifacts artifacts-zk dist typechain; do mv \"${dir}\" \"_${dir}\"; rm -rf \"_${dir}\" &; done",
2828
"clean": "rm -rf node_modules cache cache-zk artifacts artifacts-zk dist typechain",
29+
"generate-svm-assets": "sh ./scripts/generate-svm-assets.sh",
2930
"build-evm": "hardhat compile",
3031
"build-svm": "echo 'Generating IDLs...' && anchor build > /dev/null 2>&1 || true && anchor run generateExternalTypes && anchor build",
3132
"build-ts": "tsc && rsync -a --include '*/' --include '*.d.ts' --exclude '*' ./typechain ./dist/",
32-
"build": "yarn build-evm && yarn build-svm && yarn build-ts",
33+
"build": "yarn build-evm && yarn build-svm && yarn generate-svm-assets && yarn build-ts",
3334
"test-evm": "IS_TEST=true hardhat test",
3435
"test-svm": "anchor test -- --features test",
3536
"test": "yarn test-evm && yarn test-svm",
3637
"test:report-gas": "IS_TEST=true REPORT_GAS=true hardhat test",
37-
"generate-contract-types": "rm -rf typechain && TYPECHAIN=ethers yarn hardhat typechain",
38-
"prepublish": "yarn build && hardhat export --export-all ./cache/massExport.json && ts-node ./scripts/processHardhatExport.ts && prettier --write ./deployments/deployments.json && yarn generate-contract-types",
38+
"generate-evm-assets": "rm -rf typechain && TYPECHAIN=ethers yarn hardhat typechain",
39+
"prepublish": "yarn build && hardhat export --export-all ./cache/massExport.json && ts-node ./scripts/processHardhatExport.ts && prettier --write ./deployments/deployments.json && yarn generate-evm-assets",
3940
"pre-commit-hook": "sh scripts/preCommitHook.sh"
4041
},
4142
"dependencies": {

scripts/generate-svm-assets.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
3+
# Set paths for source and destination
4+
TARGET_IDL="./target/idl"
5+
TARGET_TYPES="./target/types"
6+
SVM_ASSETS="./src/svm/assets"
7+
SVM_IDL="$SVM_ASSETS/idl"
8+
SVM_TYPES="$SVM_ASSETS"
9+
IDL_OUTPUT_FILE="$SVM_IDL/index.ts"
10+
TYPES_OUTPUT_FILE="$SVM_TYPES/index.ts"
11+
12+
# Ensure the destination directories exist
13+
mkdir -p "$SVM_IDL"
14+
mkdir -p "$SVM_TYPES"
15+
16+
# --- Copy Files ---
17+
echo "Copying IDL files..."
18+
cp -r "$TARGET_IDL/"* "$SVM_IDL/"
19+
20+
echo "Copying Types files..."
21+
cp -r "$TARGET_TYPES/"* "$SVM_TYPES/"
22+
23+
# --- Generate IDL index.ts ---
24+
echo "Generating IDL index.ts..."
25+
> "$IDL_OUTPUT_FILE"
26+
27+
# Add autogenerated file note
28+
{
29+
echo "// This file has been autogenerated. Do not edit manually."
30+
echo "// Generated by a script."
31+
echo
32+
} >> "$IDL_OUTPUT_FILE"
33+
34+
IMPORTS=""
35+
EXPORTS=""
36+
37+
for file in "$SVM_IDL"/*.json; do
38+
filename=$(basename -- "$file")
39+
name="${filename%.json}"
40+
camelCaseName=$(echo "$name" | awk -F'_' '{
41+
for (i=1; i<=NF; i++) {
42+
printf toupper(substr($i,1,1)) tolower(substr($i,2));
43+
}
44+
}')
45+
IMPORTS="${IMPORTS}const ${camelCaseName}Idl = require(\"./${filename}\");\n"
46+
EXPORTS="${EXPORTS} ${camelCaseName}Idl,\n"
47+
done
48+
49+
# Write the imports to the file
50+
printf "$IMPORTS" >> "$IDL_OUTPUT_FILE"
51+
52+
# Write the exports block
53+
{
54+
echo "export {"
55+
printf "$EXPORTS" | sed '$ s/,$//'
56+
echo "};"
57+
} >> "$IDL_OUTPUT_FILE"
58+
59+
echo "IDL index.ts generated successfully at $IDL_OUTPUT_FILE"
60+
61+
# --- Generate svm-types index.ts ---
62+
echo "Generating svm-types index.ts..."
63+
> "$TYPES_OUTPUT_FILE"
64+
65+
# Add autogenerated file note
66+
{
67+
echo "// This file has been autogenerated. Do not edit manually."
68+
echo "// Generated by a script."
69+
echo
70+
} >> "$TYPES_OUTPUT_FILE"
71+
72+
# Export * from ./idl
73+
echo "export * from \"./idl\";" >> "$TYPES_OUTPUT_FILE"
74+
75+
# Export * from each .ts file in ./svm-types, removing underscores and capitalizing names
76+
for file in "$SVM_TYPES"/*.ts; do
77+
[ "$(basename -- "$file")" = "index.ts" ] && continue
78+
filename=$(basename -- "$file")
79+
name="${filename%.ts}"
80+
camelCaseName=$(echo "$name" | awk -F'_' '{
81+
for (i=1; i<=NF; i++) {
82+
printf toupper(substr($i,1,1)) tolower(substr($i,2));
83+
}
84+
}')
85+
newName="${camelCaseName}Anchor"
86+
echo "export {${camelCaseName} as ${newName}} from \"./${name}\";" >> "$TYPES_OUTPUT_FILE"
87+
done
88+
89+
echo "svm-types index.ts generated successfully at $TYPES_OUTPUT_FILE"

scripts/svm/bridgeLiabilityToHubPool.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@
2424
*/
2525

2626
import * as anchor from "@coral-xyz/anchor";
27-
import { AnchorProvider, BN, Program } from "@coral-xyz/anchor";
27+
import { AnchorProvider, BN } from "@coral-xyz/anchor";
2828
import { ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from "@solana/spl-token";
2929
import { PublicKey, SystemProgram } from "@solana/web3.js";
3030
// eslint-disable-next-line camelcase
31-
import { MessageTransmitter } from "../../target/types/message_transmitter";
32-
import { SvmSpoke } from "../../target/types/svm_spoke";
33-
// eslint-disable-next-line camelcase
3431
import {
3532
CIRCLE_IRIS_API_URL_DEVNET,
3633
CIRCLE_IRIS_API_URL_MAINNET,
@@ -46,7 +43,7 @@ import {
4643
import { TOKEN_SYMBOLS_MAP } from "@across-protocol/constants";
4744
import { getNodeUrl } from "@uma/common";
4845
import { BigNumber, ethers } from "ethers";
49-
import { TokenMessengerMinter } from "../../target/types/token_messenger_minter";
46+
import { getMessageTransmitterProgram, getSpokePoolProgram, getTokenMessengerMinterProgram } from "../../src/svm";
5047
import { BondToken__factory } from "../../typechain";
5148
import { formatUsdc, requireEnv } from "./utils/helpers";
5249

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

5754
// Get Solana programs and IDLs.
58-
const svmSpokeIdl = require("../../target/idl/svm_spoke.json");
59-
const svmSpokeProgram = new Program<SvmSpoke>(svmSpokeIdl, provider);
60-
const messageTransmitterIdl = require("../../target/idl/message_transmitter.json");
61-
const tokenMessengerMinterIdl = require("../../target/idl/token_messenger_minter.json");
55+
const svmSpokeProgram = getSpokePoolProgram(provider);
6256

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

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

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

220214
const [tokenMessengerMinterSenderAuthority] = PublicKey.findProgramAddressSync(
221215
[Buffer.from("sender_authority")],

scripts/svm/closeRelayerPdas.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
// This script closes all Relayer PDAs associated with tracking fill Status. Relayers should do this periodically to
22
// reclaim the lamports within these tracking accounts. Fill Status PDAs can be closed on the deposit has expired.
33
import * as anchor from "@coral-xyz/anchor";
4-
import { BN, Program, AnchorProvider } from "@coral-xyz/anchor";
4+
import { AnchorProvider, BN } from "@coral-xyz/anchor";
55
import { PublicKey, SystemProgram } from "@solana/web3.js";
6-
import { SvmSpoke } from "../../target/types/svm_spoke";
76
import yargs from "yargs";
87
import { hideBin } from "yargs/helpers";
9-
import { calculateRelayEventHashUint8Array, readProgramEvents } from "../../src/svm";
8+
import { calculateRelayEventHashUint8Array, getSpokePoolProgram, readProgramEvents } from "../../src/svm";
109

1110
// Set up the provider
1211
const provider = AnchorProvider.env();
1312
anchor.setProvider(provider);
14-
const idl = require("../../target/idl/svm_spoke.json");
15-
const program = new Program<SvmSpoke>(idl, provider);
13+
const program = getSpokePoolProgram(provider);
1614
const programId = program.programId;
1715

1816
// Parse arguments

0 commit comments

Comments
 (0)