deploy_pyth.rs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. use fuels::{
  2. prelude::{Address, Provider, WalletUnlocked},
  3. types::Bits256,
  4. };
  5. use pyth_sdk::pyth_utils::guardian_set_upgrade_4_addresses;
  6. use pyth_sdk::{
  7. constants::{
  8. BTC_USD_PRICE_FEED_ID, DEFAULT_VALID_TIME_PERIOD, DUMMY_CHAIN_ID, ETH_USD_PRICE_FEED_ID,
  9. USDC_USD_PRICE_FEED_ID,
  10. },
  11. pyth_utils::{update_data_bytes, DataSource, Pyth},
  12. };
  13. #[tokio::main]
  14. async fn main() {
  15. dotenv::dotenv().ok();
  16. println!("🔮 Testnet Pyth deploy action");
  17. let provider = Provider::connect("https://testnet.fuel.network")
  18. .await
  19. .unwrap();
  20. let admin_pk = std::env::var("ADMIN").expect("ADMIN environment variable missing");
  21. let admin =
  22. WalletUnlocked::new_from_private_key(admin_pk.parse().unwrap(), Some(provider.clone()));
  23. println!("Admin address = 0x{}\n", Address::from(admin.address()));
  24. let pyth = Pyth::deploy(admin).await.unwrap();
  25. let governance_data_source: DataSource = DataSource {
  26. chain_id: 1,
  27. emitter_address: Bits256::from_hex_str(
  28. "5635979a221c34931e32620b9293a463065555ea71fe97cd6237ade875b12e9e",
  29. )
  30. .unwrap(),
  31. };
  32. let wormhole_governance_data_source: DataSource = DataSource {
  33. chain_id: 1,
  34. emitter_address: Bits256([
  35. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  36. 0, 0, 4,
  37. ]),
  38. };
  39. let _ = pyth
  40. .constructor(
  41. governance_data_source,
  42. wormhole_governance_data_source,
  43. DEFAULT_VALID_TIME_PERIOD,
  44. guardian_set_upgrade_4_addresses(),
  45. 4,
  46. DUMMY_CHAIN_ID,
  47. )
  48. .await
  49. .unwrap();
  50. //check GS
  51. let gsi = pyth.current_guardian_set_index().await.unwrap().value;
  52. println!("gsi: {:?}", gsi);
  53. let update_data = update_data_bytes(None).await.unwrap();
  54. let update_fee_return = pyth.update_fee(&update_data).await.unwrap();
  55. let fee = update_fee_return.value;
  56. //print fee
  57. println!("fee: {:?}", fee);
  58. let btc_price_feed = Bits256::from_hex_str(BTC_USD_PRICE_FEED_ID).unwrap();
  59. let eth_price_feed = Bits256::from_hex_str(ETH_USD_PRICE_FEED_ID).unwrap();
  60. let usdc_price_feed = Bits256::from_hex_str(USDC_USD_PRICE_FEED_ID).unwrap();
  61. let _ = pyth.update_price_feeds(fee, &update_data).await.unwrap();
  62. println!("Pyth address = 0x{:?}\n", pyth.instance.contract_id().hash);
  63. println!(
  64. "BTC price {:?}",
  65. pyth.price(btc_price_feed).await.unwrap().value
  66. );
  67. println!(
  68. "ETH price {:?}",
  69. pyth.price(eth_price_feed).await.unwrap().value
  70. );
  71. println!(
  72. "USDC price {:?}",
  73. pyth.price(usdc_price_feed).await.unwrap().value
  74. );
  75. }