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

solana: Update documentation for v3.0.0 changes #592

Merged
merged 8 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Transceiver.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

The Transceiver is intended to offer a protocol-agnostic interface for sending and receiving cross-chain messages. For Native Token Transfers, this entails initiating attestation generation on the source chain, verifying the resulting attestation on the destination chain, and delivering the message to the associated `NttManager`.

In the provided implementations ([EVM](/evm/src/Transceiver/Transceiver.sol)/[SVM](/solana/programs/example-native-token-transfers/src/transceivers/wormhole/)), Transceiver are intended to have a many-to-one or one-to-one relationship with Managers.
In the provided implementations ([EVM](/evm/src/Transceiver/Transceiver.sol)/[SVM](/solana/programs/ntt-transceiver/src/wormhole/)), Transceivers are intended to have a many-to-one relationship with Managers.

## Message Specification

Expand Down
14 changes: 10 additions & 4 deletions evm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,25 +166,31 @@ Install Foundry tools(https://book.getfoundry.sh/getting-started/installation),
Run the following command to install necessary dependencies and to build the smart contracts:

```shell
$ make build-evm
$ make build
```

### Test

To run the full evm test-suite run the following command:

```shell
$ make test-evm
$ make test
```

The test-suite includes unit tests, along with property-based fuzz tests, and integration-tests.

### Format

To format the files run this command from the root directory.
To check for format errors run the following command:

```shell
$ make fix-fmt
$ make lint
```

To format the files run the following command:

```shell
$ make fix-lint
```

### Gas Snapshots
Expand Down
8 changes: 4 additions & 4 deletions solana/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.DEFAULT_GOAL = build
.PHONY: build cargo-build anchor-build prod-build test cargo-test anchor-test idl sdk clean node_modules lint cargo-lint anchor-lint fix-lint

#find and convert version line:
# turn `const VERSION: &str = "major.minor.patch";` into `major_minor_patch`
#use make functions to minimize dependence on shell
# Find and convert version line:
# Turn `const VERSION: &str = "major.minor.patch";` into `major_minor_patch`
# Use make functions to minimize dependence on shell
VERSION = $(subst .,_,$(subst ;,,$(subst ",,$(lastword \
$(shell grep "const VERSION" programs/example-native-token-transfers/src/lib.rs) \
))))
Expand All @@ -18,7 +18,7 @@ build: cargo-build anchor-build
cargo-build:
BPF_OUT_DIR="$(pwd)/target/deploy" cargo build-sbf

# after building, remove the generics from the idl file. This is necessary as of anchor 0.29.0,
# After building, remove the generics from the idl file. This is necessary as of anchor 0.29.0,
# because the javascript library does not support generics yet, and just panics
anchor-build:
anchor build --arch sbf
Expand Down
112 changes: 61 additions & 51 deletions solana/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
# Solana

## Prequisities

Ensure that you are using the correct version of the Solana and Anchor CLI tools by consulting `Anchor.toml`.

```toml
[toolchain]
anchor_version = "0.29.0" # CLI
solana_version = "1.18.10"
```

You will also need to install the toolchain listed in `rust-toolchain`. You can verify this by running:

```sh
rustup show
```

## Design Overview

### Message Lifecycle (Solana)
Expand All @@ -41,14 +25,14 @@ The program checks rate limits via the `consume_or_delay` function during the tr

If the transfer amount fits within the current capacity:

- Reduce the current capacity
- Refill the inbound capacity for the destination chain
- Reduce the current capacity.
- Refill the inbound capacity for the destination chain.
- Add the transfer to the outbox with `release_timestamp` set to the current timestamp, so it can be released immediately.

If the transfer amount does not fit within the current capacity:

- If `shouldQueue = true`, add the transfer to the outbox with `release_timestamp` set to the current timestamp plus the configured `RATE_LIMIT_DURATION`.
- If `shouldQueue = false`, revert with a `TransferExceedsRateLimit` error
- If `should_queue = true`, add the transfer to the outbox with `release_timestamp` set to the current timestamp plus the configured `RATE_LIMIT_DURATION`.
- If `should_queue = false`, revert with a `TransferExceedsRateLimit` error.

3. **Send**

Expand Down Expand Up @@ -76,7 +60,7 @@ The following will be produced in the program logs:
Program log: Instruction: ReceiveMessage
```

[`redeem`] checks the inbound rate limit and places the message in an Inbox. Logic works the same as the outbound rate limit we mentioned previously.
[`redeem`] checks the inbound rate limit and places the message in an Inbox. The logic works the same as the outbound rate limit we mentioned previously.

The following will be produced in the program logs:

Expand Down Expand Up @@ -109,51 +93,77 @@ The additional payload field should then have your custom struct available every

You can then modify [release_outbound](./programs/example-native-token-transfers/src/transceivers/wormhole/instructions/release_outbound.rs) and [redeem](./programs/example-native-token-transfers/src/instructions/redeem.rs) to generate and process the additional payload.

## Testing
## SPL Multisig Support

Using [SPL Multisig](https://docs.rs/spl-token/latest/spl_token/state/struct.Multisig.html), you can enable multiple minters on Solana. For example, this allows NTT to burn/mint tokens without being the only authority to do so, i.e. the asset issuer can also retain mint authority.

1. **Create valid SPL Multisig**

The SPL Multisig should meet the following criteria to qualify as a valid mint authority for NTT:

- Number of signers required ([m](https://docs.rs/spl-token/latest/spl_token/state/struct.Multisig.html#structfield.m)) should be `1`
- One of the [signers](https://docs.rs/spl-token/latest/spl_token/state/struct.Multisig.html#structfield.signers) must be the `token_authority` PDA

2. **Set valid SPL Multisig as mint authority**

You can set the created multisig as the mint authority via the [`accept_token_authority`] instruction.

> If the current mint authority is also an SPL Multisig, use the [`accept_token_authority_from_multisig`] instruction instead.

3. **Use [`*_multisig`] instruction variants**

The test files are loacated in the `sdk/solana/__tests__/` directory
To initialize NTT, use the [`initialize_multisig`] instruction instead.

In order to run them, the Solana programs must be built and their IDL made available to the SDK.
In `burning` mode, to release the inbound transfer and the mint tokens to the recipient, use the [`release_inbound_mint_multisig`] instruction instead.

To ensure the SDK has the generated IDL, run the tests with the make command:
## Prerequisites

### Installation

Ensure that you are using the correct version of the Solana and Anchor CLI tools by consulting `Anchor.toml`.

```toml
[toolchain]
anchor_version = "0.29.0" # CLI
solana_version = "1.18.10"
```

Install the toolchain listed in `rust-toolchain`. You can verify this by running:

```sh
make test
rustup show
```

### Troubleshooting
Install [`jq`](https://jqlang.github.io/jq/) and [`tsx`](https://www.npmjs.com/package/tsx) globally as they are required by build scripts.

<details>
<summary><code>make: *** No rule to make target `test'. Stop.</code></summary>
### Build

- Ensure `Makefile` has target `test`
</details>
Run the following command to install necessary dependencies and to build the programs:

<details>
<summary><code>tsx: command not found</code></summary>
```sh
make build
```

- Screenshot:
<img src="images/tsx-command-not-found.png" alt="tsx command not found screenshot">
- Update `Makefile` ([line #29](https://github.com/wormhole-foundation/example-native-token-transfers/blob/main/solana/Makefile#L29)) from:
### Test

```sh
tsx scripts/regenerateIdl.ts $$jsonfile > $$tsfile; \
```
Run the following command to generate the IDL and run the full Solana test-suite:

to:
```sh
make test
```

```sh
npx tsx scripts/regenerateIdl.ts $$jsonfile > $$tsfile; \
```
The test-suite includes cargo unit tests and Anchor integration tests.

</details>
### Format

<details>
<summary><code>Lifecycle script `build:esm` failed with error</code></summary>
Run the following command to check for lint errors:

- Screenshot:
<img src="images/lifecycle-script.png" alt="lifecycle script screenshot">
- This occurs due to Typescript files failing compilation.
- [`patch-idl` script](https://github.com/wormhole-foundation/example-native-token-transfers/blob/main/solana/scripts/patch-idl) requires [`jq`](https://jqlang.github.io/jq/) to be installed. Install `jq` and retry.
```sh
make lint
```

Run the following command to fix lint errors:

</details>
```sh
make fix-lint
```
Binary file removed solana/images/lifecycle-script.png
Binary file not shown.
Binary file removed solana/images/tsx-command-not-found.png
Binary file not shown.
Loading