Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
resolver = "2"
members = [
"contracts/common",
"contracts/escrow",
"contracts/milestones",
"contracts/maintenance-pool",
Expand Down
12 changes: 12 additions & 0 deletions contracts/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "mergefi-common"
version.workspace = true
edition.workspace = true
license.workspace = true
publish.workspace = true

[lib]
crate-type = ["rlib"]

[dependencies]
soroban-sdk = { workspace = true }
22 changes: 22 additions & 0 deletions contracts/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![no_std]

use soroban_sdk::{Address, Env, IntoVal, Val};

/// Trait to identify the Admin key for a contract's DataKey enum
pub trait AdminKey {
fn admin_key() -> Self;
}

pub fn require_admin<K>(env: &Env) -> Option<Address>
where
K: AdminKey + IntoVal<Env, Val>,
{
env.storage().instance().get(&K::admin_key())
}

pub fn extend_ttl<K>(env: &Env, key: &K)
where
K: IntoVal<Env, Val>,
{
env.storage().persistent().extend_ttl(key, 100_000, 500_000);
}
1 change: 1 addition & 0 deletions contracts/escrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
soroban-sdk = { workspace = true }
mergefi-common = { path = "../common" }

[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }
Expand Down
7 changes: 2 additions & 5 deletions contracts/escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,12 @@ pub(crate) fn compute_split(
}

pub(crate) fn require_admin(env: &Env) -> Result<Address, Error> {
env.storage()
.instance()
.get(&DataKey::Admin)
.ok_or(Error::NotInitialized)
mergefi_common::require_admin::<DataKey>(env).ok_or(Error::NotInitialized)
}

/// Extends the TTL of a persistent entry so escrow records aren't archived
/// while still active. Threshold/extend values are conservative defaults
/// suitable for a multi-month bounty lifecycle.
pub(crate) fn extend_ttl(env: &Env, key: &DataKey) {
env.storage().persistent().extend_ttl(key, 100_000, 500_000);
mergefi_common::extend_ttl(env, key);
}
6 changes: 6 additions & 0 deletions contracts/escrow/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ pub enum DataKey {
FeeBps,
Escrow(u64),
}

impl mergefi_common::AdminKey for DataKey {
fn admin_key() -> Self {
DataKey::Admin
}
}
1 change: 1 addition & 0 deletions contracts/maintenance-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
soroban-sdk = { workspace = true }
mergefi-common = { path = "../common" }

[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }
Expand Down
7 changes: 2 additions & 5 deletions contracts/maintenance-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,9 @@ impl MaintenancePoolContract {
}

fn require_admin(env: &Env) -> Result<Address, Error> {
env.storage()
.instance()
.get(&DataKey::Admin)
.ok_or(Error::NotInitialized)
mergefi_common::require_admin::<DataKey>(env).ok_or(Error::NotInitialized)
}

fn extend_ttl(env: &Env, key: &DataKey) {
env.storage().persistent().extend_ttl(key, 100_000, 500_000);
mergefi_common::extend_ttl(env, key);
}
6 changes: 6 additions & 0 deletions contracts/maintenance-pool/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ pub enum DataKey {
Pool(u64),
Deposit(u64, u32), // (pool_id, deposit_index)
}

impl mergefi_common::AdminKey for DataKey {
fn admin_key() -> Self {
DataKey::Admin
}
}
1 change: 1 addition & 0 deletions contracts/milestones/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
soroban-sdk = { workspace = true }
mergefi-common = { path = "../common" }

[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }
Expand Down
7 changes: 2 additions & 5 deletions contracts/milestones/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,9 @@ fn compute_split(
}

fn require_admin(env: &Env) -> Result<Address, Error> {
env.storage()
.instance()
.get(&DataKey::Admin)
.ok_or(Error::NotInitialized)
mergefi_common::require_admin::<DataKey>(env).ok_or(Error::NotInitialized)
}

fn extend_ttl(env: &Env, key: &DataKey) {
env.storage().persistent().extend_ttl(key, 100_000, 500_000);
mergefi_common::extend_ttl(env, key);
}
6 changes: 6 additions & 0 deletions contracts/milestones/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ pub enum DataKey {
Milestone(u64),
IssueStatus(u64, u64), // (milestone_id, issue_id)
}

impl mergefi_common::AdminKey for DataKey {
fn admin_key() -> Self {
DataKey::Admin
}
}
Loading