devnet_setup.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/usr/bin/env bash
  2. # This script configures the devnet for test transfers with hardcoded addresses.
  3. set -eu
  4. # Configure CLI (works the same as upstream Solana CLI)
  5. mkdir -p ~/.config/solana/cli
  6. cat <<EOF > ~/.config/solana/cli/config.yml
  7. json_rpc_url: "http://127.0.0.1:8899"
  8. websocket_url: ""
  9. keypair_path: /usr/src/solana/keys/solana-devnet.json
  10. EOF
  11. # Static key for the mint so it always has the same address
  12. cat <<EOF > token.json
  13. [179,228,102,38,68,102,75,133,127,56,63,167,143,42,59,29,220,215,100,149,220,241,176,204,154,241,168,147,195,139,55,100,22,88,9,115,146,64,160,172,3,185,132,64,254,137,133,84,142,58,166,131,205,13,77,157,245,181,101,150,105,250,163,1]
  14. EOF
  15. # Static key for the NFT mint so it always has the same address
  16. cat <<EOF > nft.json
  17. [155,117,110,235,96,214,56,128,109,79,49,209,212,13,134,5,43,123,213,68,21,156,128,100,95,8,43,51,188,230,21,197,156,0,108,72,200,203,243,56,73,203,7,163,249,54,21,156,197,35,249,89,28,177,153,154,189,69,137,14,197,254,233,183]
  18. EOF
  19. # Static key for the 2nd NFT mint so it always has the same address
  20. cat <<EOF > nft2.json
  21. [40,74,92,250,81,56,202,67,129,124,193,219,24,161,198,98,191,214,136,7,112,26,72,17,33,249,24,225,183,237,27,216,11,179,26,170,82,220,3,253,152,185,151,186,12,21,138,161,175,46,180,3,167,165,70,51,128,45,237,143,146,49,34,180]
  22. EOF
  23. # Static key for the 3nd NFT mint so it always has the same address
  24. cat <<EOF > nft3.json
  25. [237,91,99,59,171,108,222,79,145,161,183,11,19,47,174,103,92,35,34,136,123,190,169,63,107,117,190,109,0,240,233,8,139,177,114,106,66,109,185,216,58,55,83,115,160,194,236,49,7,252,13,189,79,81,65,124,113,183,96,26,14,98,166,118]
  26. EOF
  27. # Constants
  28. cli_address=6sbzC1eH4FTujJXWj51eQe25cYvr4xfXbJ1vAj7j2k5J
  29. bridge_address=Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o
  30. nft_bridge_address=NFTWqJR8YnRVqPDvTJrYuLrQDitTG5AScqbeghi4zSA
  31. token_bridge_address=B6RHG3mfcckmrYN1UhmJzyS1XX3fZKbkeUcpJe9Sy3FE
  32. recipient_address=90F8bf6A479f320ead074411a4B0e7944Ea8c9C1
  33. chain_id_ethereum=2
  34. account2=7HrnXGAzG6mV93Lumk7yfyrNk2bpstq8YyesqojLj8mG
  35. # load the .env file with the devent init data
  36. source .env
  37. retry () {
  38. while ! $@; do
  39. sleep 1
  40. done
  41. }
  42. # Fund our account (as defined in solana/keys/solana-devnet.json).
  43. retry solana airdrop 1000
  44. # Fund our second account
  45. solana airdrop 1000 "$account2"
  46. # Create a new SPL token
  47. token=$(spl-token create-token -- token.json | grep 'Creating token' | awk '{ print $3 }')
  48. echo "Created token $token"
  49. # Create token account
  50. account=$(spl-token create-account "$token" | grep 'Creating account' | awk '{ print $3 }')
  51. echo "Created token account $account"
  52. # Mint new tokens owned by our CLI account
  53. spl-token mint "$token" 10000000000 "$account"
  54. # Create meta for token
  55. token-bridge-client create-meta "$token" "Solana Test Token" "SOLT" ""
  56. # Create a new SPL NFT
  57. nft=$(spl-token create-token --decimals 0 -- nft.json | grep 'Creating token' | awk '{ print $3 }')
  58. echo "Created NFT $nft"
  59. # Create NFT account
  60. nft_account=$(spl-token create-account "$nft" | grep 'Creating account' | awk '{ print $3 }')
  61. echo "Created NFT account $nft_account"
  62. # Mint new NFT owned by our CLI account
  63. spl-token mint "$nft" 1 "$nft_account"
  64. # Create meta for token
  65. token-bridge-client create-meta "$nft" "Not a PUNK🎸" "PUNK🎸" "https://wrappedpunks.com:3000/api/punks/metadata/39"
  66. nft=$(spl-token create-token --decimals 0 -- nft2.json | grep 'Creating token' | awk '{ print $3 }')
  67. echo "Created NFT $nft"
  68. nft_account=$(spl-token create-account "$nft" | grep 'Creating account' | awk '{ print $3 }')
  69. echo "Created NFT account $nft_account"
  70. spl-token mint "$nft" 1 "$nft_account"
  71. token-bridge-client create-meta "$nft" "Not a PUNK 2🎸" "PUNK2🎸" "https://wrappedpunks.com:3000/api/punks/metadata/51"
  72. # Create a new SPL NFT
  73. nft=$(spl-token create-token --decimals 0 -- nft3.json | grep 'Creating token' | awk '{ print $3 }')
  74. echo "Created NFT $nft"
  75. # Create NFT account
  76. nft_account=$(spl-token create-account --owner "$account2" "$nft" | grep 'Creating account' | awk '{ print $3 }')
  77. echo "Created NFT account $nft_account"
  78. # Mint new NFT owned by our second account
  79. spl-token mint "$nft" 1 "$nft_account"
  80. # Create meta for token
  81. token-bridge-client create-meta "$nft" "Not a PUNK3🎸" "PUNK3🎸" "https://wrappedpunks.com:3000/api/punks/metadata/69"
  82. # Create the bridge contract at a known address
  83. # OK to fail on subsequent attempts (already created).
  84. retry client create-bridge "$bridge_address" "$INIT_SIGNERS_CSV" 86400 100
  85. # Initialize the token bridge
  86. retry token-bridge-client create-bridge "$token_bridge_address" "$bridge_address"
  87. # Initialize the NFT bridge
  88. retry token-bridge-client create-bridge "$nft_bridge_address" "$bridge_address"
  89. # next we get all the registration VAAs from the environment
  90. # if a new VAA is added, this will automatically pick it up
  91. VAAS=$(set | grep "REGISTER_.*_VAA" | grep -v SOL | cut -d '=' -f1)
  92. # reset the builtin SECONDS timer (it's incremented once a second).
  93. SECONDS=0
  94. # use 'worm' to submit each registration VAA
  95. echo "Running chain registrations in parallel"
  96. # we'll send the registration calls in parallel, but we want to wait on them at
  97. # the end, so we collect the PIDs
  98. registration_pids=()
  99. for VAA in $VAAS
  100. do
  101. VAA=${!VAA}
  102. worm submit $VAA --chain solana --network devnet &
  103. registration_pids+=( $! )
  104. done
  105. # wait on registration calls
  106. for pid in "${registration_pids[@]}"; do
  107. wait $pid
  108. done
  109. echo "Registrations successfully completed in $SECONDS seconds."
  110. # Let k8s startup probe succeed
  111. nc -k -l -p 2000