Skip to content

Commit

Permalink
feature: after mainnet deployment, final code changes we did during l…
Browse files Browse the repository at this point in the history
…aunch
  • Loading branch information
newbreedofgeek committed Aug 27, 2024
1 parent c368b8d commit d33fb68
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ test-ledger
.yarn

Anchor.toml
.env
.env

*wallet*.json
2 changes: 1 addition & 1 deletion Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ seeds = false
skip-lint = false

[programs.localnet]
bridge_program = "bitH2bkiBmbcio1riko9qLhkgKdAtY4BEx61ZQuvrfj"
bridge_program = "4wDs9FnvdksFXy69UKVgi7WWqtYJmbM6TiMCEWY9wJz9"

[registry]
url = "https://api.apr.dev"
Expand Down
115 changes: 106 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Let's run the test once to see what happens.

### Install `anchor`

First, make sure that `anchor` is installed:
First, make sure that `anchor` and the `solana-cli` is installed:

Install `avm`:

Expand All @@ -57,13 +57,18 @@ $ avm use 0.29.0
...
```

install Solana CLI as per here: https://docs.solanalabs.com/cli/install

#### Verify the Installation

Check if Anchor is successfully installed:

```bash
$ anchor --version
anchor-cli 0.29.0

$ solana --version
solana-cli 1.18.15 (src:767d24e5; feat:4215500110, client:SolanaLabs)
```

### Install Dependencies
Expand All @@ -76,13 +81,19 @@ $ yarn

### Build `bridge-program`

Remove any `target` folder if needed or rename if you want to keep it (i.e. version upgrade). You also need to delete it the first time you deploy this program, as only doing this will generate a new program_id needed for next step. For upgrades and followups, you don't need to delete the folder.

```bash
$ anchor build
```

#### Update `program_id`

Get the public key of the deploy key. This keypair is generated automatically so a different key is exptected:
Get the public key of the deploy key. This keypair is generated automatically so a different key is expected:

```bash
$ anchor keys list
bridge-program: DRxp3EJv4hGQDze6Evf515KE1YwVgYNv6PiDp1dqF4pK
bridge-program: 4wDs9FnvdksFXy69UKVgi7WWqtYJmbM6TiMCEWY9wJz9
```

Replace the default value of `program_id` with this new value:
Expand All @@ -106,27 +117,89 @@ declare_id!("DRxp3EJv4hGQDze6Evf515KE1YwVgYNv6PiDp1dqF4pK");
...
```

Build the program:
ALSO, note that you need to "hardcode" the General Admin wallet in constants.rs. This general admin is the one that can call initializeContract.

```
pub const ADMIN_PUBKEY: Pubkey = pubkey!("AxDG4CDKrn8s3a1caY69nQYCjR8YnxqjhMPwhUGFKL2Q");
```

We we re-Build the program: (DO NOT delete the target folder this time before running)

```
$ anchor build
```

### Deploy `bridge-program`

Let's deploy the program.
Let's deploy the program using anchor...

```
$ solana config set --url localhost
```

```
$ anchor deploy
or else, you can update Anchor.toml `cluster = "devnet"` or `mainnet` (mainnet-beta?)

you can also toggle deploying wallet by `wallet = "usb://ledger?key=1"` or `wallet = "~/.config/solana/id.json"`

NOTE: that we can't deploy via Anchor as we found it not too stable, so we used the Solana CLI.

- First, let's generate a new key pair that we will use to deploy the "buffer", once you have it, save it somewhere safe. You will also need a decent amount of SOL in this account (around 3 should do for this program), as it will be used as "rent" for the code. then we set this as the default solana cli wallet for now (or else it will use our standard id.json wallet). Note that on top of setting the custom wallet, you also need to confirm the RPC and config is correct for the mainnet deployment as it defaults to devnet.

Update RPC for devnet/testnet/mainnet by editing the config file here:
`vi /Users/markpaul/.config/solana/cli/config.yml` (and then check via `solana config get`)

Set the default wallet like so:
`solana config set -k /location_of/custom_wallet.json`

The below keys have been backed-up in storage.

[devnet]
`solana config set -k /Users/markpaul/Documents/Source/Software/core-sol-bridge-sc/devnet_interim_first_deployer_wallet_9tSsTbCZEGMgZYALathtBbqmELY7BefFbQQ4gasXGBAo.json`

[mainnet]
`solana config set -k /Users/markpaul/Documents/Source/Software/core-sol-bridge-sc/interim_buffer_deployer_mainnet_FVnq4TFB39W8xEY36rhwFnScpkGzc59jhL3EuFi6K8Nb.json`

- Next, we use this key pair to generate the buffer
`solana program write-buffer "./target/deploy/bridge_program.so"`

Note that if you don't have enough SOL, then you will see some error like `Error: Account XXX has insufficient funds for spend (2.80402392 SOL) + fee (0.002 SOL)`

Program Id: DRxp3EJv4hGQDze6Evf515KE1YwVgYNv6PiDp1dqF4pK
In this situation, you need to get more SOL.. but you don't lose what you used, you can do this to close the buffer (note that this closes ALL buffers on this authority -- so if this is not the plan, then you can try and recover the buffer after increasing your SOL. The console should give you tips on how to recover the buffer when the error is hit)
`solana program close --buffers`

Deploy success
if it's a success, the console will give us the buffer like so as an e.g. `Buffer: 85me4UW2ytQmUnzTAHtFvLoZf85D6qhzwgcvUusAByb2`

[devnet]
https://explorer.solana.com/address/85me4UW2ytQmUnzTAHtFvLoZf85D6qhzwgcvUusAByb2?cluster=devnet

[testnet]
`Buffer: 4c5UDi4inDoauN9HShH4CrF5SfEmXxnPAZguKvMK4ocd`
https://explorer.solana.com/address/4c5UDi4inDoauN9HShH4CrF5SfEmXxnPAZguKvMK4ocd?cluster=testnet

[mainnet]
`Buffer: GohVs4cC1WMtTjBgvKA7byWpWsyd9zHy85Z21JtuDPm`
https://explorer.solana.com/address/GohVs4cC1WMtTjBgvKA7byWpWsyd9zHy85Z21JtuDPm

if you notice, the Deploy Authority, is our custom new HOT wallet. Maybe we want to move this to a Cold wallet for security? if so we can do this:

[devnet]
`solana program set-buffer-authority 85me4UW2ytQmUnzTAHtFvLoZf85D6qhzwgcvUusAByb2 --new-buffer-authority 4FeJ53a5QZQFroVgQ5pKFNsu7BEV5AoxHMGhsNKhETYt`

[mainnet]
`solana program set-buffer-authority GohVs4cC1WMtTjBgvKA7byWpWsyd9zHy85Z21JtuDPm --new-buffer-authority 4FeJ53a5QZQFroVgQ5pKFNsu7BEV5AoxHMGhsNKhETYt`

- And finally, we deploy the program from the buffer:
[devnet]
`solana program deploy --program-id "./target/deploy/bridge_program-keypair.json" --buffer 85me4UW2ytQmUnzTAHtFvLoZf85D6qhzwgcvUusAByb2 --upgrade-authority "usb://ledger?key=2"`

[mainnet]
`solana program deploy --program-id "./target/deploy/bridge_program-keypair.json" --buffer GohVs4cC1WMtTjBgvKA7byWpWsyd9zHy85Z21JtuDPm --upgrade-authority "usb://ledger?key=2"`

You should finally get the program deployed and see something like:

```
✅ Approved
Program Id: 4wDs9FnvdksFXy69UKVgi7WWqtYJmbM6TiMCEWY9wJz9
```

### Test `bridge-program`
Expand Down Expand Up @@ -202,3 +275,27 @@ To sign and send a transaction using ledger Nano S, do the following:

1. `Allow blind signing` in the ledger settings.
2. `Pubkey length` set to `Long` in the ledger settings.

### The following commands will bootstrap our program (Check Notion for full steps)

- Step 1: run initializeContract with the params

```bash
cargo run initializeContract --url https://api.devnet.solana.com --keypair <GENERAL_ADMIN_PK> <RELAYER_PUK> <FEE_COLLECTOR_PUK> 0 10000000000 100000000000000 iTHdo2NJbcxy5rKKMwNaffUxZA2zK6DPJirgLgwRkA1

cargo run initializeContract --url https://api.devnet.solana.com --keypair "usb://ledger?key=3" 88Ga1dz27cDXt7srwEy2WtKufA218EgdVGUKjMvTjH4u 93i5uFs7ztSpHcnhTQj8Fr67a3kBedFoMkJUB4b4xdWe 0 10000000000 100000000000000 iTHdo2NJbcxy5rKKMwNaffUxZA2zK6DPJirgLgwRkA1
```

- Step 2: run addLiquidity with the params -- BUT we can do this via the token snippets as well
cargo run addLiquidity --url https://api.devnet.solana.com --keypair "usb://ledger?key=3"

- Step 3: run unpause when ready

```bash
cargo run relayerUnpause --url https://api.devnet.solana.com --keypair "usb://ledger?key=3"
```

- Step 4: run unpause when ready (this is what allows the public to deposit)
```bash
cargo run publicUnpause --url https://api.devnet.solana.com --keypair "usb://ledger?key=3"
```
2 changes: 1 addition & 1 deletion programs/bridge-program/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use solana_program::pubkey;
use solana_program::pubkey::Pubkey;

pub const ADMIN_PUBKEY: Pubkey = pubkey!("FuMzWZ2bi7QmquTzCrjvsEbmyCt1tF78idxGJQhjTiWu");
pub const ADMIN_PUBKEY: Pubkey = pubkey!("AxDG4CDKrn8s3a1caY69nQYCjR8YnxqjhMPwhUGFKL2Q");
2 changes: 1 addition & 1 deletion programs/bridge-program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ solana_security_txt::security_txt! {
auditors: "https://itheum.io/audits"
}

declare_id!("bitH2bkiBmbcio1riko9qLhkgKdAtY4BEx61ZQuvrfj");
declare_id!("4wDs9FnvdksFXy69UKVgi7WWqtYJmbM6TiMCEWY9wJz9");

#[program]
pub mod bridge_program {
Expand Down

0 comments on commit d33fb68

Please sign in to comment.