-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathvolatility_incentive_coston2.rs
More file actions
95 lines (91 loc) · 3.68 KB
/
Copy pathvolatility_incentive_coston2.rs
File metadata and controls
95 lines (91 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// THIS IS EXAMPLE CODE. DO NOT USE THIS CODE IN PRODUCTION.
use alloy::{
network::EthereumWallet, primitives::address, primitives::U256, providers::ProviderBuilder,
signers::local::PrivateKeySigner, sol,
};
use eyre::Result;
// Declare this manually to avoid some strange nested type errors
sol! {
#[sol(rpc)]
interface FastUpdatesIncentiveManager {
type SampleSize is uint256;
type Range is uint256;
type Fee is uint256;
type Precision is uint256;
type Scale is uint256;
struct IncentiveOffer {
Range rangeIncrease;
Range rangeLimit;
}
constructor(
address _governanceSettings,
address _initialGovernance,
address _addressUpdater,
SampleSize _ss,
Range _r,
SampleSize _sil,
Range _ril,
Fee _x,
Fee _rip,
uint256 _dur
);
function getCurrentSampleSizeIncreasePrice()
external view returns (Fee);
function getExpectedSampleSize()
external view returns (SampleSize);
function getRange()
external view returns (Range);
function getScale()
external view returns (Scale);
function offerIncentive(IncentiveOffer calldata _offer)
external payable;
}
}
#[tokio::main]
async fn main() -> Result<()> {
// Get private key from environment
let private_key = std::env::var("ACCOUNT_PRIVATE_KEY")?;
// FastUpdatesIncentiveManager address (Flare Testnet Coston2)
// See https://dev.flare.network/ftso/solidity-reference
let incentive_address = address!("d648e8ACA486Ce876D641A0F53ED1F2E9eF4885D");
// Set up wallet and provider
let signer: PrivateKeySigner = private_key.parse().unwrap();
let wallet = EthereumWallet::from(signer.clone());
let provider = ProviderBuilder::new()
.wallet(wallet)
.connect_http("https://coston2-api.flare.network/ext/C/rpc".parse()?);
// Set up contract instance
let incentive = FastUpdatesIncentiveManager::new(incentive_address, provider);
// Get the current sample size, sample size increase price, range, and scale
let sample_size_increase_price = incentive.getCurrentSampleSizeIncreasePrice().call().await?;
let expected_sample_size = incentive.getExpectedSampleSize().call().await?;
let range = incentive.getRange().call().await?;
let scale = incentive.getScale().call().await?;
println!("Sample Size Increase Price: {sample_size_increase_price:?}");
println!("Current Sample Size: {expected_sample_size:?}");
println!("Current Range: {range:?}");
println!("Current Scale: {scale:?}");
// Offer the incentive
let offer = FastUpdatesIncentiveManager::IncentiveOffer {
rangeIncrease: U256::from(0),
rangeLimit: U256::from(0),
};
let tx_hash = incentive
.offerIncentive(offer)
.value(sample_size_increase_price)
.send()
.await?
.watch()
.await?;
println!("Offer Incentive Tx Hash: {tx_hash:?}");
// Get the new sample size increase price, sample size, range, and scale
let sample_size_increase_price = incentive.getCurrentSampleSizeIncreasePrice().call().await?;
let exp_sample_size = incentive.getExpectedSampleSize().call().await?;
let range = incentive.getRange().call().await?;
let scale = incentive.getScale().call().await?;
println!("Sample Size Increase Price: {sample_size_increase_price:?} ");
println!("Current Sample Size: {exp_sample_size:?}");
println!("Current Range: {range:?}");
println!("Current Scale: {scale:?}");
Ok(())
}