diff --git a/.gitignore b/.gitignore index 3e8ecd3..f13b654 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ test-ledger .yarn Anchor.toml -.env \ No newline at end of file +.env + +*wallet*.json \ No newline at end of file diff --git a/Anchor.toml b/Anchor.toml index 4bcfad1..d592356 100644 --- a/Anchor.toml +++ b/Anchor.toml @@ -5,7 +5,7 @@ seeds = false skip-lint = false [programs.localnet] -bridge_program = "bitH2bkiBmbcio1riko9qLhkgKdAtY4BEx61ZQuvrfj" +bridge_program = "4wDs9FnvdksFXy69UKVgi7WWqtYJmbM6TiMCEWY9wJz9" [registry] url = "https://api.apr.dev" diff --git a/README.md b/README.md index 0638573..88f83de 100644 --- a/README.md +++ b/README.md @@ -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`: @@ -57,6 +57,8 @@ $ 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: @@ -64,6 +66,9 @@ 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 @@ -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: @@ -106,7 +117,13 @@ 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 @@ -114,19 +131,75 @@ $ 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` @@ -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 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" + ``` diff --git a/programs/bridge-program/src/constants.rs b/programs/bridge-program/src/constants.rs index 0d162fb..5f818d1 100644 --- a/programs/bridge-program/src/constants.rs +++ b/programs/bridge-program/src/constants.rs @@ -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"); diff --git a/programs/bridge-program/src/lib.rs b/programs/bridge-program/src/lib.rs index 864fa0d..dd73537 100644 --- a/programs/bridge-program/src/lib.rs +++ b/programs/bridge-program/src/lib.rs @@ -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 {