Skip to content

Commit

Permalink
Update governance functions/proposal json commands for Cellar V2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrit committed Jul 11, 2023
1 parent 53207df commit 3bd8981
Show file tree
Hide file tree
Showing 15 changed files with 873 additions and 222 deletions.
142 changes: 71 additions & 71 deletions proto/steward/v4/cellar_v2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,18 @@ message CellarV2_2 {
AddPosition add_position = 1;
// Represents function `callOnAdaptor(AdaptorCall[] memory data)`
CallOnAdaptor call_on_adaptor = 2;
// Represents function `removePosition(uint256 index)`
// Represents function `removePosition(uint256 index, bool inDebtArray)`
RemovePosition remove_position = 3;
// Represents function `removeAdaptorFromCatalogue(address adaptor)`
RemoveAdaptorFromCatalogue remove_adaptor_from_catalogue = 4;
// Represents function `removePositionFromCatalogue(uint32 positionId)`
RemovePositionFromCatalogue remove_position_from_catalogue = 5;
// Represents function `setHoldingPosition(uint32 position_id)`
SetHoldingPosition set_holding_position = 4;
SetHoldingPosition set_holding_position = 6;
// Represents function `setStrategistPayoutAddress(address payout)`
SetStrategistPayoutAddress set_strategist_payout_address = 5;
SetStrategistPayoutAddress set_strategist_payout_address = 7;
// Represents function `swapPositions(uint256 index1, uint256 index2)`
SwapPositions swap_positions = 6;
// Represents function `setRebalanceDeviation(uint265)`
SetRebalanceDeviation set_rebalance_deviation = 7;
// Represents function `setShareLockPeriod(uint256 newLock)`
SetShareLockPeriod set_share_lock_period = 8;
// Represents function `initiateShutdown()`
InitiateShutdown initiate_shutdown = 9;
// Represents function `setStrategistPlatformCut(uint64 cut)`
SetStrategistPlatformCut set_strategist_platform_cut = 10;
// Represents function `liftShutdown()`
LiftShutdown lift_shutdown = 11;
SwapPositions swap_positions = 8;
}
}

Expand Down Expand Up @@ -265,6 +259,24 @@ message CellarV2_2 {
bool in_debt_array = 2;
}

/*
* Allows callers to remove adaptors from this cellar's catalogue
*
* Represents function `removeAdaptorFromCatalogue(address adaptor)`
*/
message RemoveAdaptorFromCatalogue {
string adaptor = 1;
}

/*
* Allows caller to remove positions from this cellar's catalogue
*
* Represents function `removePositionFromCatalogue(uint32 positionId)`
*/
message RemovePositionFromCatalogue {
uint32 position_id = 1;
}

/*
* Set the holding position used of the cellar.
*
Expand Down Expand Up @@ -298,49 +310,6 @@ message CellarV2_2 {
bool in_debt_array = 3;
}

/*
* Allows share lock period to be updated.
*
* Represents function `setShareLockPeriod()`
*/
message SetShareLockPeriod {
string new_lock = 1;
}

/*
* Changes the cellar's allowed rebalance deviation, which is the percent the total assets of a cellar may deviate
* during a `callOnAdaptor`(rebalance) call. The maximum allowed deviation is 100000000000000000 (0.1e18), or 10%.
*
* Represents function `setRebalanceDeviation(uint256)`
*/
message SetRebalanceDeviation {
string new_deviation = 1;
}

/*
* Shutdown the cellar. Used in an emergency or if the cellar has been deprecated.
*
* Represents function `initiateShutdown()`
*/
message InitiateShutdown {}

/*
* Allows strategist to set the platform cut for the cellar.
*
* Represents function `setStrategistPlatformCut(uint64 cut)`
*/
message SetStrategistPlatformCut {
// The new strategist platform cut
uint64 new_cut = 1;
}

/*
* Allows the owner to restart a shut down Cellar
*
* Represents function `liftShutdown()`
*/
message LiftShutdown {}

/*
* Allows caller to call multiple functions in a single TX.
*
Expand All @@ -361,14 +330,20 @@ message CellarV2_2Governance {
AddAdaptorToCatalogue add_adaptor_to_catalogue = 1;
// Represents function `addPositionToCatalogue(uint32 positionId)`
AddPositionToCatalogue add_position_to_catalogue = 2;
// Represents function `removeAdaptorFromCatalogue(address adaptor)`
RemoveAdaptorFromCatalogue remove_adaptor_from_catalogue = 3;
// Represents function `removePositionFromCatalogue(uint32 positionId)`
RemovePositionFromCatalogue remove_position_from_catalogue = 4;
// Represents function `setRebalanceDeviation(uint265)`
SetRebalanceDeviation set_rebalance_deviation = 3;
// Represents function `setShareLockPeriod(uint256 newLock)`
SetShareLockPeriod set_share_lock_period = 4;
// Represents function `setStrategistPlatformCut(uint64 cut)`
SetStrategistPlatformCut set_strategist_platform_cut = 5;
// Represents function `initiateShutdown()`
InitiateShutdown initiate_shutdown = 6;
// Represents function `liftShutdown()`
LiftShutdown lift_shutdown = 7;
// Represents function `forcePositionOut(uint32 index, uint32 positionId, bool inDebtArray)`
ForcePositionOut force_position_out = 5;
ForcePositionOut force_position_out = 8;
// Represents function `toggleIgnorePause(bool ignore)`
ToggleIgnorePause toggle_ignore_pause = 6;
ToggleIgnorePause toggle_ignore_pause = 9;
}

/*
Expand All @@ -390,23 +365,48 @@ message CellarV2_2Governance {
}

/*
* Allows callers to remove adaptors from this cellar's catalogue
* Allows share lock period to be updated.
*
* Represents function `removeAdaptorFromCatalogue(address adaptor)`
* Represents function `setShareLockPeriod()`
*/
message RemoveAdaptorFromCatalogue {
string adaptor = 1;
message SetShareLockPeriod {
string new_lock = 1;
}

/*
* Allows caller to remove positions from this cellar's catalogue
* Changes the cellar's allowed rebalance deviation, which is the percent the total assets of a cellar may deviate
* during a `callOnAdaptor`(rebalance) call. The maximum allowed deviation is 100000000000000000 (0.1e18), or 10%.
*
* Represents function `removePositionFromCatalogue(uint32 positionId)`
* Represents function `setRebalanceDeviation(uint256)`
*/
message RemovePositionFromCatalogue {
uint32 position_id = 1;
message SetRebalanceDeviation {
string new_deviation = 1;
}

/*
* Shutdown the cellar. Used in an emergency or if the cellar has been deprecated.
*
* Represents function `initiateShutdown()`
*/
message InitiateShutdown {}

/*
* Allows strategist to set the platform cut for the cellar.
*
* Represents function `setStrategistPlatformCut(uint64 cut)`
*/
message SetStrategistPlatformCut {
// The new strategist platform cut
uint64 new_cut = 1;
}

/*
* Allows the owner to restart a shut down Cellar
*
* Represents function `liftShutdown()`
*/
message LiftShutdown {}

/*
* Allows caller to force a position out of the cellar
*
Expand Down
149 changes: 78 additions & 71 deletions src/cellars/cellar_v2_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ pub fn get_encoded_function(call: FunctionCall, cellar_id: String) -> Result<Vec

Ok(CellarV2_2Calls::RemovePosition(call).encode())
}
Function::RemoveAdaptorFromCatalogue(params) => {
log_cellar_call(
CELLAR_NAME,
&RemoveAdaptorFromCatalogueCall::function_name(),
&cellar_id,
);
let call = RemoveAdaptorFromCatalogueCall {
adaptor: sp_call_parse_address(params.adaptor)?,
};

Ok(CellarV2_2Calls::RemoveAdaptorFromCatalogue(call).encode())
}
Function::RemovePositionFromCatalogue(params) => {
log_cellar_call(
CELLAR_NAME,
&RemovePositionFromCatalogueCall::function_name(),
&cellar_id,
);
let call = RemovePositionFromCatalogueCall {
position_id: params.position_id,
};

Ok(CellarV2_2Calls::RemovePositionFromCatalogue(call).encode())
}
Function::SetHoldingPosition(params) => {
log_cellar_call(
CELLAR_NAME,
Expand Down Expand Up @@ -122,67 +146,6 @@ pub fn get_encoded_function(call: FunctionCall, cellar_id: String) -> Result<Vec

Ok(CellarV2_2Calls::SwapPositions(call).encode())
}
Function::SetShareLockPeriod(params) => {
log_cellar_call(
CELLAR_NAME,
&SetShareLockPeriodCall::function_name(),
&cellar_id,
);
let call = SetShareLockPeriodCall {
new_lock: string_to_u256(params.new_lock)?,
};

Ok(CellarV2_2Calls::SetShareLockPeriod(call).encode())
}
// This will ultimately need to be a governance function, but for Seven Sea's live testing we are keeping
// it here until they get a feel for what an appropriate value is.
Function::SetRebalanceDeviation(params) => {
log_cellar_call(
CELLAR_NAME,
&SetRebalanceDeviationCall::function_name(),
&cellar_id,
);

let new_deviation = string_to_u256(params.new_deviation)?;
if new_deviation > U256::from(5000000000000000u64) {
return Err(ErrorKind::SPCallError
.context("deviation must be 0.5% or less".to_string())
.into());
}

let call = SetRebalanceDeviationCall { new_deviation };

Ok(CellarV2_2Calls::SetRebalanceDeviation(call).encode())
}
Function::InitiateShutdown(_) => {
log_cellar_call(
CELLAR_NAME,
&InitiateShutdownCall::function_name(),
&cellar_id,
);
let call = InitiateShutdownCall {};

Ok(CellarV2_2Calls::InitiateShutdown(call).encode())
}
Function::SetStrategistPlatformCut(params) => {
log_cellar_call(
CELLAR_NAME,
&SetStrategistPlatformCutCall::function_name(),
&cellar_id,
);

let call = SetStrategistPlatformCutCall {
cut: params.new_cut,
};

Ok(CellarV2_2Calls::SetStrategistPlatformCut(call).encode())
}
Function::LiftShutdown(_) => {
log_cellar_call(CELLAR_NAME, &LiftShutdownCall::function_name(), &cellar_id);
let call = LiftShutdownCall {};

Ok(CellarV2_2Calls::LiftShutdown(call).encode())
}
}
}

Expand Down Expand Up @@ -218,31 +181,75 @@ pub fn get_encoded_governance_call(

Ok(CellarV2_2Calls::AddPositionToCatalogue(call).encode())
}
GovernanceFunction::RemoveAdaptorFromCatalogue(params) => {
GovernanceFunction::SetShareLockPeriod(params) => {
log_governance_cellar_call(
proposal_id,
CELLAR_NAME,
&RemoveAdaptorFromCatalogueCall::function_name(),
&SetShareLockPeriodCall::function_name(),
cellar_id,
);
let call = RemoveAdaptorFromCatalogueCall {
adaptor: sp_call_parse_address(params.adaptor)?,
let call = SetShareLockPeriodCall {
new_lock: string_to_u256(params.new_lock)?,
};

Ok(CellarV2_2Calls::RemoveAdaptorFromCatalogue(call).encode())
Ok(CellarV2_2Calls::SetShareLockPeriod(call).encode())
}
GovernanceFunction::RemovePositionFromCatalogue(params) => {
// This will ultimately need to be a governance function, but for Seven Sea's live testing we are keeping
// it here until they get a feel for what an appropriate value is.
GovernanceFunction::SetRebalanceDeviation(params) => {
log_governance_cellar_call(
proposal_id,
CELLAR_NAME,
&RemovePositionFromCatalogueCall::function_name(),
&SetRebalanceDeviationCall::function_name(),
cellar_id,
);
let call = RemovePositionFromCatalogueCall {
position_id: params.position_id,

let new_deviation = string_to_u256(params.new_deviation)?;
if new_deviation > U256::from(5000000000000000u64) {
return Err(ErrorKind::SPCallError
.context("deviation must be 0.5% or less".to_string())
.into());
}

let call = SetRebalanceDeviationCall { new_deviation };

Ok(CellarV2_2Calls::SetRebalanceDeviation(call).encode())
}
GovernanceFunction::InitiateShutdown(_) => {
log_governance_cellar_call(
proposal_id,
CELLAR_NAME,
&InitiateShutdownCall::function_name(),
cellar_id,
);
let call = InitiateShutdownCall {};

Ok(CellarV2_2Calls::InitiateShutdown(call).encode())
}
GovernanceFunction::SetStrategistPlatformCut(params) => {
log_governance_cellar_call(
proposal_id,
CELLAR_NAME,
&SetStrategistPlatformCutCall::function_name(),
cellar_id,
);

let call = SetStrategistPlatformCutCall {
cut: params.new_cut,
};

Ok(CellarV2_2Calls::RemovePositionFromCatalogue(call).encode())
Ok(CellarV2_2Calls::SetStrategistPlatformCut(call).encode())
}
GovernanceFunction::LiftShutdown(_) => {
log_governance_cellar_call(
proposal_id,
CELLAR_NAME,
&LiftShutdownCall::function_name(),
cellar_id,
);
let call = LiftShutdownCall {};

Ok(CellarV2_2Calls::LiftShutdown(call).encode())
}
GovernanceFunction::ForcePositionOut(params) => {
log_governance_cellar_call(
Expand Down
1 change: 1 addition & 0 deletions src/commands/cork_proposal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod aave_v2_stablecoin;
mod cellar_v1;
mod cellar_v2;
mod cellar_v2_2;

use crate::{
commands::cork_proposal::aave_v2_stablecoin::AaveV2StablecoinCellarCmd, proto::GovernanceCall,
Expand Down
Loading

0 comments on commit 3bd8981

Please sign in to comment.