Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 156 queue reserve inits #158

Merged
merged 9 commits into from
Dec 21, 2023
Merged

Conversation

markuspluna
Copy link
Contributor

Addresses Issue 156 adding reserve initialization queues by adding reserve init queuing to the Pool contract for new reserve additions and requiring initial pool reserves to be added as part of pool initialization

@markuspluna markuspluna requested a review from mootz12 December 13, 2023 04:22
@markuspluna markuspluna changed the base branch from main to status-management-updates December 13, 2023 04:25
/// TODO: Duplicated from pool/storage.rs. Can this be moved to a common location?
#[derive(Clone)]
#[contracttype]
pub struct ReserveConfig {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be fetched from the Pool WASM, to avoid duplication. The Pool Factory is already dependent on it.

/// ### Panics
/// If the reserve is not queued for initialization
/// or is already setup
/// or has invalid metadata
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should validate the metadata on queue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That duplicates code since we reuse the initialize function which validates metadata

@@ -8,3 +8,6 @@ pub const SCALAR_7: i128 = 1_0000000;

// seconds per year
pub const SECONDS_PER_YEAR: i128 = 31536000;

// approximate week in blocks assuming 5 seconds per block
pub const WEEK_IN_BLOCKS: u32 = 120960;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A week seems like a really long time, no?

Consider a DAO doing this:

  1. Create proposal for queueing the init_reserve (2 days before voting, 3 day voting period, 2 day timelock) (7 days)
  2. Wait ~ 1 day
  3. Create another proposal for submitting the init (7 day gov period)

So its a 15 day, 2 proposal process to add a reserve to the pool, assuming they are smart enough to double dip the timelock and proposal period.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will most DAO's have a mandatory 2 day period before voting? I made initialization permissionless so I think it's important the queue time is longer than a typical DAO vote -> execution time so they can cancel initializations if a malicious one snuck in without anyone noticing

Comment on lines 72 to 79
/// (Admin only) Cancels the queued initialization of a reserve in the pool
///
/// ### Arguments
/// * `asset` - The underlying asset to add as a reserve
///
/// ### Panics
/// If the caller is not the admin or the reserve is not queued for initialization
fn cancel_init_reserve(e: Env, asset: Address);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's potentially problematic not to have one - consider someone sneaks through a bad DAO proposal or tricks a multisig into adding a reserve - note that executing the queued initialization is not permissioned

);
execute_queued_reserve_initialization(&e, &asset_id_0);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a test for cancel if we deem it should be kept

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_execute_cancel_queued_reserve_initialization

Base automatically changed from status-management-updates to main December 19, 2023 13:50
pool/src/pool/config.rs Outdated Show resolved Hide resolved
let mut reserve = pool.load_reserve(e, asset);
reserve.store(e);
index = reserve.index;
let reserve_config = storage::get_res_config(e, asset);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is on the reserve object you already read

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it isn't - we don't expose config on the reserve object

);
execute_queued_reserve_initialization(&e, &asset_id_0);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing this?

pool/src/pool/status.rs Show resolved Hide resolved
pool/src/storage.rs Outdated Show resolved Hide resolved
@markuspluna markuspluna merged commit b977cd7 into main Dec 21, 2023
3 checks passed
@markuspluna markuspluna deleted the Issue-156-queue-reserve-inits branch December 21, 2023 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants