83 lines
2.5 KiB
Plaintext
83 lines
2.5 KiB
Plaintext
// File: contracts/ActivelyValidatedService/sources/AVS.move
|
|
|
|
import 0x1::Signer;
|
|
import 0x1::Account;
|
|
import 0x1::Transaction;
|
|
import 0x1::Event;
|
|
|
|
module ActivelyValidatedService {
|
|
|
|
// Struct to define the AVS service
|
|
struct AVS {
|
|
owner: signer,
|
|
validators: vector<address>,
|
|
active: bool,
|
|
validation_criteria: vector<u8>,
|
|
last_validated_timestamp: u64,
|
|
stake_amount: u64,
|
|
staked_tokens: vector<u8>,
|
|
active_validations: vector<Transaction>
|
|
}
|
|
|
|
// Initialize a new AVS instance
|
|
public fun init(owner: signer, validators: vector<address>, validation_criteria: vector<u8>, stake_amount: u64) {
|
|
assert(signer != owner);
|
|
self.owner = owner;
|
|
self.validators = validators;
|
|
self.validation_criteria = validation_criteria;
|
|
self.stake_amount = stake_amount;
|
|
self.staked_tokens = [];
|
|
self.active_validations = [];
|
|
self.active = true;
|
|
self.last_validated_timestamp = 0;
|
|
}
|
|
|
|
// Add a new validator to the AVS service
|
|
public fun add_validator(validator: address) {
|
|
assert(signer == self.owner);
|
|
self.validators.push_back(validator);
|
|
}
|
|
|
|
// Remove a validator from the AVS service
|
|
public fun remove_validator(validator: address) {
|
|
assert(signer == self.owner);
|
|
self.validators = vector::remove(self.validators, validator);
|
|
}
|
|
|
|
// Stake tokens to participate in AVS validation
|
|
public fun stake_tokens(tokens: vector<u8>) {
|
|
assert(tokens.length() > 0);
|
|
self.staked_tokens = tokens;
|
|
}
|
|
|
|
// Start a validation process
|
|
public fun start_validation(transaction: Transaction) {
|
|
assert(self.active);
|
|
assert(vector::length(self.staked_tokens) >= self.stake_amount);
|
|
self.active_validations.push_back(transaction);
|
|
}
|
|
|
|
// Complete validation by validators
|
|
public fun complete_validation(validated: u64, transaction: Transaction) {
|
|
assert(self.active);
|
|
self.last_validated_timestamp = validated;
|
|
self.active_validations = vector::remove(self.active_validations, transaction);
|
|
}
|
|
|
|
// Deactivate the AVS service
|
|
public fun deactivate() {
|
|
assert(signer == self.owner);
|
|
self.active = false;
|
|
}
|
|
|
|
// Event emitted when a validation is completed
|
|
event ValidationCompleted(u64, Transaction);
|
|
|
|
// Event emitted when AVS is deactivated
|
|
event AVSDeactivated();
|
|
|
|
// Event emitted when a validator is added or removed
|
|
event ValidatorChanged(address);
|
|
|
|
}
|