Skip to content
Open
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
121 changes: 118 additions & 3 deletions contracts/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

mod storage;

use soroban_sdk::{Address, Env, IntoVal, String, TryFromVal, Val, Vec};
use soroban_sdk::{Address, BytesN, Env, IntoVal, String, TryFromVal, Val, Vec};
use storage as proxy_storage;
use subtrackr_types::{
Interval, Plan, ScheduledUpgrade, StorageKey, Subscription, Timestamp, UpgradeAction,
UpgradeEvent,
ChargeCommitment, Interval, MevProtectionConfig, Plan, ScheduledUpgrade, StorageKey,
Subscription, Timestamp, UpgradeAction, UpgradeEvent,
};

fn current_proxy_address(env: &Env) -> Address {
Expand Down Expand Up @@ -377,6 +377,86 @@ impl UpgradeableProxy {
);
}

pub fn configure_mev_protection(env: Env, admin: Address, config: MevProtectionConfig) {
let proxy_addr = current_proxy_address(&env);
let storage_addr = proxy_storage::storage_address(&env);
invoke_impl::<()>(
&env,
"configure_mev_protection",
soroban_sdk::vec![
&env,
proxy_addr.into_val(&env),
storage_addr.into_val(&env),
admin.into_val(&env),
config.into_val(&env)
],
);
}

pub fn commit_charge(env: Env, subscription_id: u64, commitment: BytesN<32>) {
let proxy_addr = current_proxy_address(&env);
let storage_addr = proxy_storage::storage_address(&env);
invoke_impl::<()>(
&env,
"commit_charge",
soroban_sdk::vec![
&env,
proxy_addr.into_val(&env),
storage_addr.into_val(&env),
subscription_id.into_val(&env),
commitment.into_val(&env)
],
);
}

pub fn hash_charge_commitment(
env: Env,
subscription_id: u64,
max_charge_amount: i128,
salt: BytesN<32>,
) -> BytesN<32> {
let proxy_addr = current_proxy_address(&env);
let storage_addr = proxy_storage::storage_address(&env);
invoke_impl(
&env,
"hash_charge_commitment",
soroban_sdk::vec![
&env,
proxy_addr.into_val(&env),
storage_addr.into_val(&env),
subscription_id.into_val(&env),
max_charge_amount.into_val(&env),
salt.into_val(&env)
],
)
}

pub fn reveal_charge(
env: Env,
subscription_id: u64,
salt: BytesN<32>,
max_charge_amount: i128,
observed_gas_price: u64,
private_mempool: bool,
) {
let proxy_addr = current_proxy_address(&env);
let storage_addr = proxy_storage::storage_address(&env);
invoke_impl::<()>(
&env,
"reveal_charge",
soroban_sdk::vec![
&env,
proxy_addr.into_val(&env),
storage_addr.into_val(&env),
subscription_id.into_val(&env),
salt.into_val(&env),
max_charge_amount.into_val(&env),
observed_gas_price.into_val(&env),
private_mempool.into_val(&env)
],
);
}

pub fn create_plan(
env: Env,
merchant: Address,
Expand Down Expand Up @@ -672,4 +752,39 @@ impl UpgradeableProxy {
soroban_sdk::vec![&env, proxy_addr.into_val(&env), storage_addr.into_val(&env)],
)
}

pub fn get_mev_protection_config(env: Env) -> MevProtectionConfig {
let proxy_addr = current_proxy_address(&env);
let storage_addr = proxy_storage::storage_address(&env);
invoke_impl(
&env,
"get_mev_protection_config",
soroban_sdk::vec![&env, proxy_addr.into_val(&env), storage_addr.into_val(&env)],
)
}

pub fn get_charge_commitment(env: Env, subscription_id: u64) -> Option<ChargeCommitment> {
let proxy_addr = current_proxy_address(&env);
let storage_addr = proxy_storage::storage_address(&env);
invoke_impl(
&env,
"get_charge_commitment",
soroban_sdk::vec![
&env,
proxy_addr.into_val(&env),
storage_addr.into_val(&env),
subscription_id.into_val(&env)
],
)
}

pub fn get_mev_alert_count(env: Env) -> u64 {
let proxy_addr = current_proxy_address(&env);
let storage_addr = proxy_storage::storage_address(&env);
invoke_impl(
&env,
"get_mev_alert_count",
soroban_sdk::vec![&env, proxy_addr.into_val(&env), storage_addr.into_val(&env)],
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4240,6 +4240,57 @@
},
"failed_call": false
},
{
"event": {
"ext": "v0",
"contract_id": "0000000000000000000000000000000000000000000000000000000000000006",
"type_": "diagnostic",
"body": {
"v0": {
"topics": [
{
"symbol": "fn_call"
},
{
"bytes": "0000000000000000000000000000000000000000000000000000000000000005"
},
{
"symbol": "instance_get"
}
],
"data": {
"vec": [
{
"symbol": "MevProtectionConfig"
}
]
}
}
}
},
"failed_call": false
},
{
"event": {
"ext": "v0",
"contract_id": "0000000000000000000000000000000000000000000000000000000000000005",
"type_": "diagnostic",
"body": {
"v0": {
"topics": [
{
"symbol": "fn_return"
},
{
"symbol": "instance_get"
}
],
"data": "void"
}
}
},
"failed_call": false
},
{
"event": {
"ext": "v0",
Expand Down Expand Up @@ -5709,4 +5760,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7315,6 +7315,57 @@
},
"failed_call": false
},
{
"event": {
"ext": "v0",
"contract_id": "0000000000000000000000000000000000000000000000000000000000000006",
"type_": "diagnostic",
"body": {
"v0": {
"topics": [
{
"symbol": "fn_call"
},
{
"bytes": "0000000000000000000000000000000000000000000000000000000000000005"
},
{
"symbol": "instance_get"
}
],
"data": {
"vec": [
{
"symbol": "MevProtectionConfig"
}
]
}
}
}
},
"failed_call": false
},
{
"event": {
"ext": "v0",
"contract_id": "0000000000000000000000000000000000000000000000000000000000000005",
"type_": "diagnostic",
"body": {
"v0": {
"topics": [
{
"symbol": "fn_return"
},
{
"symbol": "instance_get"
}
],
"data": "void"
}
}
},
"failed_call": false
},
{
"event": {
"ext": "v0",
Expand Down Expand Up @@ -8729,6 +8780,57 @@
},
"failed_call": false
},
{
"event": {
"ext": "v0",
"contract_id": "0000000000000000000000000000000000000000000000000000000000000006",
"type_": "diagnostic",
"body": {
"v0": {
"topics": [
{
"symbol": "fn_call"
},
{
"bytes": "0000000000000000000000000000000000000000000000000000000000000005"
},
{
"symbol": "instance_get"
}
],
"data": {
"vec": [
{
"symbol": "MevProtectionConfig"
}
]
}
}
}
},
"failed_call": false
},
{
"event": {
"ext": "v0",
"contract_id": "0000000000000000000000000000000000000000000000000000000000000005",
"type_": "diagnostic",
"body": {
"v0": {
"topics": [
{
"symbol": "fn_return"
},
{
"symbol": "instance_get"
}
],
"data": "void"
}
}
},
"failed_call": false
},
{
"event": {
"ext": "v0",
Expand Down Expand Up @@ -10790,4 +10892,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4283,6 +4283,57 @@
},
"failed_call": false
},
{
"event": {
"ext": "v0",
"contract_id": "0000000000000000000000000000000000000000000000000000000000000006",
"type_": "diagnostic",
"body": {
"v0": {
"topics": [
{
"symbol": "fn_call"
},
{
"bytes": "0000000000000000000000000000000000000000000000000000000000000005"
},
{
"symbol": "instance_get"
}
],
"data": {
"vec": [
{
"symbol": "MevProtectionConfig"
}
]
}
}
}
},
"failed_call": false
},
{
"event": {
"ext": "v0",
"contract_id": "0000000000000000000000000000000000000000000000000000000000000005",
"type_": "diagnostic",
"body": {
"v0": {
"topics": [
{
"symbol": "fn_return"
},
{
"symbol": "instance_get"
}
],
"data": "void"
}
}
},
"failed_call": false
},
{
"event": {
"ext": "v0",
Expand Down Expand Up @@ -5835,4 +5886,4 @@
"failed_call": false
}
]
}
}
Loading