diff --git a/Stellar-contracts-v1/mock-amm/src/lib.rs b/Stellar-contracts-v1/mock-amm/src/lib.rs index c39c556..612a885 100644 --- a/Stellar-contracts-v1/mock-amm/src/lib.rs +++ b/Stellar-contracts-v1/mock-amm/src/lib.rs @@ -3,7 +3,18 @@ //! Mock AMM pool for testing wPi -> MockUSDC swaps. //! Hardcodes a 1:1 swap rate (or configurable) for testnet simulation without complex math. -use soroban_sdk::{contract, contracterror, contractimpl, contracttype, token, Address, Env}; +use soroban_sdk::{ + contract, contracterror, contractimpl, contracttype, token, Address, BytesN, Env, +}; + +/// SHA-256 hash of the Stellar mainnet network passphrase +/// ("Public Global Stellar Network ; September 2015"). This is the value +/// `env.ledger().network_id()` returns when a contract is running on +/// mainnet. mock-amm is test-only and must never be initialized there. +const MAINNET_NETWORK_ID: [u8; 32] = [ + 0x7a, 0xc3, 0x39, 0x97, 0x54, 0x4e, 0x31, 0x75, 0xd2, 0x66, 0xbd, 0x02, 0x24, 0x39, 0xb2, 0x2c, + 0xdb, 0x16, 0x50, 0x8c, 0x01, 0x16, 0x3f, 0x26, 0xe5, 0xcb, 0x2a, 0x3e, 0x10, 0x45, 0xa9, 0x79, +]; #[contracttype] #[derive(Clone)] @@ -20,6 +31,7 @@ pub enum Error { NotAdmin = 1, InsufficientLiquidity = 2, SlippageExceeded = 3, + MainnetNotSupported = 4, } #[contract] @@ -33,7 +45,10 @@ impl MockAmm { token_in: Address, token_out: Address, rate_bps: u32, - ) { + ) -> Result<(), Error> { + if env.ledger().network_id() == BytesN::from_array(&env, &MAINNET_NETWORK_ID) { + return Err(Error::MainnetNotSupported); + } if env.storage().instance().has(&DataKey::Admin) { panic!("already initialized"); } @@ -42,6 +57,7 @@ impl MockAmm { env.storage().instance().set(&DataKey::TokenIn, &token_in); env.storage().instance().set(&DataKey::TokenOut, &token_out); env.storage().instance().set(&DataKey::Rate, &rate_bps); + Ok(()) } /// Swap token_in (wPi) for token_out (MockUSDC) diff --git a/scripts/deploy_mainnet.sh b/scripts/deploy_mainnet.sh index bce04ec..5164b22 100755 --- a/scripts/deploy_mainnet.sh +++ b/scripts/deploy_mainnet.sh @@ -11,10 +11,8 @@ SOURCE_ACCOUNT="${STELLAR_ACCOUNT:-${ADMIN_IDENTITY:-}}" ADMIN_ADDRESS="${ADMIN_ADDRESS:-}" RPC_URL="${STELLAR_RPC_URL:-}" DEPLOY_AMM="${DEPLOY_AMM:-false}" -RATE_BPS="${RATE_BPS:-1000000}" WPI_WASM="${WPI_WASM:-${CONTRACT_DIR}/target/wasm32-unknown-unknown/release/wpi_token.wasm}" -AMM_WASM="${AMM_WASM:-${CONTRACT_DIR}/target/wasm32-unknown-unknown/release/mock_amm.wasm}" NETWORK_ARGS=(--network "$NETWORK" --rpc-url "$RPC_URL" --network-passphrase "$NETWORK_PASSPHRASE") @@ -31,6 +29,11 @@ ensure_cli() { } require_mainnet_inputs() { + if [[ "$DEPLOY_AMM" == "true" ]]; then + echo "ERROR: mock-amm is test-only and must never be deployed to mainnet. Unset DEPLOY_AMM." >&2 + exit 1 + fi + if [[ -z "$SOURCE_ACCOUNT" ]]; then echo "ERROR: set STELLAR_ACCOUNT or ADMIN_IDENTITY to the mainnet signing identity." >&2 exit 1 @@ -120,25 +123,8 @@ WPI_CONTRACT_ID="$(deploy_uploaded_wasm WPI "$WPI_HASH")" echo "== Initialize wPI contract ==" invoke_contract "$WPI_CONTRACT_ID" initialize --admin "$ADMIN_ADDRESS" -if [[ "$DEPLOY_AMM" == "true" ]]; then - AMM_HASH="$(upload_wasm MOCK_AMM "$AMM_WASM")" - MOCK_AMM_CONTRACT_ID="$(deploy_uploaded_wasm MOCK_AMM "$AMM_HASH")" - - echo "== Initialize optional AMM contract ==" - invoke_contract "$MOCK_AMM_CONTRACT_ID" initialize \ - --admin "$ADMIN_ADDRESS" \ - --token_in "$WPI_CONTRACT_ID" \ - --rate_bps "$RATE_BPS" -fi - cat <