Skip to content

Commit 2fa21d0

Browse files
committed
readme: add Solana message lifecycle
Signed-off-by: bingyuyap <bingyu.yap.21@gmail.com>
1 parent 1470fc6 commit 2fa21d0

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

README.md

+67
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,73 @@ emit MessageAlreadyExecuted(sourceManagerAddress, digest);
6464
``` solidity
6565
emit TransferRedeemed(digest);
6666
```
67+
68+
69+
### Solana
70+
71+
1. Sending
72+
73+
A client calls the [`transfer_lock`] or [`transfer_burn`] instruction depending on the mode the program was in. The client must specify the amount of the transfer, the recipient chain, the recipient address on the recipient chain, and the boolean flag `should_queue` to specify whether the if the transfer should be queued if there is a rate limit.
74+
75+
> Using the wrong transfer instruction, i.e. [`transfer_lock`] for a program that is in "burning" mode, will result in `InvalidMode` error.
76+
77+
Depending on the mode and instruction, the following will be produced in the program logs:
78+
79+
```
80+
Program log: Instruction: TransferLock
81+
Program log: Instruction: TransferBurn
82+
```
83+
84+
The transfer is also added into an Outbox via the `insert_into_outbox` method, where the rate limit is checked against. An Outbox is a Solana Account which holds details of the outbound messages.
85+
86+
2. Rate Limiting
87+
88+
When the `consume_or_delay` function is invoked by the transfer instruction, the program checks if the transfer amount fits within the current capacity. If it does, the outbound capacity is reduced by the transfer amount and the transfer proceeds immediately. Inbound capacity is also refilled by the same amount. If not, the transfer is delayed by 24 hours.
89+
90+
> When `revert_on_delay` is true, the transaction will revert if the release timestamp has not been reached. When `revert_on_delay` is false, the transaction succeeds, but the outbound release is not performed.
91+
92+
3. Transmit
93+
94+
The message transmission is initiated through [`release_outbound`] instruction. Message to be transmitted is constructed based on the `OutboxItem`, which contains details about the transfer, including the recipient, the amount, and the recipient chain. The message is then transmitted to the Wormhole network using the `post_message` function.
95+
96+
The following will be produced in the program logs:
97+
98+
```
99+
Program log: Instruction: ReleaseOutbound
100+
```
101+
102+
4. Receive
103+
104+
Similar to EVM, [`receive_wormhole_message`] is the entrypoint for receiving a message on Solana. It takes a message that has been relayed from another blockchain stores it in the `transceiver_message` account.
105+
106+
The following will be produced in the program logs:
107+
108+
```
109+
Program log: Instruction: ReceiveMessage
110+
```
111+
112+
[`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.
113+
114+
The following will be produced in the program logs:
115+
116+
```
117+
Program log: Instruction: Redeem
118+
```
119+
120+
5. Mint or Unlock
121+
122+
The inbound transfer is released and the tokens are unlocked or minted to the recipient (depending ont the mode) through either [`release_inbound_mint`] (if the mode is `burning`) or [`release_inbound_unlock`] (if the mode is `locking`). Similar to transfer, using the wrong transfer instruction, i.e. [`release_inbound_mint`] for a program that is in "locking" mode, will result in `InvalidMode` error.
123+
124+
125+
> When `revert_on_delay` is true, the transaction will revert if the release timestamp has not been reached. When `revert_on_delay` is false, the transaction succeeds, but the minting/unlocking is not performed.
126+
127+
Depending on the mode and instruction, the following will be produced in the program logs:
128+
129+
```
130+
Program log: Instruction: ReleaseInboundMint
131+
Program log: Instruction: ReleaseInboundUnlock
132+
```
133+
67134
#### Installation
68135

69136
Install [Foundry](https://book.getfoundry.sh/getting-started/installation)

0 commit comments

Comments
 (0)