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
57 changes: 57 additions & 0 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Contracts

on:
push:
branches: [ main ]
tags:
- 'v*'
pull_request:
branches: [ main ]

jobs:
build:
name: Build WASM
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown

- name: Install Stellar CLI
run: |
cargo install --locked stellar-cli --features opt

- name: Build Contracts
run: make build

deploy:
name: Deploy to Testnet
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown

- name: Install Stellar CLI
run: |
cargo install --locked stellar-cli --features opt

- name: Build Contracts
run: make build

- name: Deploy
env:
STELLAR_ACCOUNT_SECRET: ${{ secrets.STELLAR_ACCOUNT_SECRET }}
run: |
# Configure identity
stellar keys add default --secret-key $STELLAR_ACCOUNT_SECRET
# Run deployment script
cd packages/contracts && bash scripts/deploy.sh
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: fmt fmt-check clippy build test integration-test clean
.PHONY: fmt fmt-check clippy build test integration-test clean deploy-testnet deploy-all

CARGO := cargo
CONTRACTS_DIR := packages/contracts
Expand All @@ -24,3 +24,8 @@ integration-test:

clean:
cd $(CONTRACTS_DIR) && $(CARGO) clean

deploy-testnet:
cd $(CONTRACTS_DIR) && bash scripts/deploy.sh

deploy-all: build deploy-testnet
4 changes: 4 additions & 0 deletions packages/contracts/contracts.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[testnet]
vault = ""
vault_token = ""
yield_registry = ""
58 changes: 58 additions & 0 deletions packages/contracts/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

# Exit on error
set -e

NETWORK="testnet"
RPC_URL="https://soroban-testnet.stellar.org:443"
NETWORK_PASSPHRASE="Test SDF Network ; September 2015"
SOURCE_ACCOUNT="default" # Assumes 'default' identity is configured in stellar-cli

# Directory where WASM files are located
WASM_DIR="../target/wasm32-unknown-unknown/release"
CONFIG_FILE="../contracts.toml"

echo "Deploying contracts to $NETWORK..."

# Function to deploy and return contract ID
deploy_contract() {
local wasm_path=$1
echo "Deploying $(basename "$wasm_path")..."

# Install WASM and get hash
local wasm_hash=$(stellar contract install \
--network "$NETWORK" \
--source "$SOURCE_ACCOUNT" \
--wasm "$wasm_path")

# Deploy contract and get ID
local contract_id=$(stellar contract deploy \
--network "$NETWORK" \
--source "$SOURCE_ACCOUNT" \
--wasm-hash "$wasm_hash")

echo "$contract_id"
}

# 1. Deploy Vault Token
VAULT_TOKEN_WASM="$WASM_DIR/vault_token.wasm"
VAULT_TOKEN_ID=$(deploy_contract "$VAULT_TOKEN_WASM")
echo "Vault Token ID: $VAULT_TOKEN_ID"

# 2. Deploy Yield Registry
YIELD_REGISTRY_WASM="$WASM_DIR/yield_registry.wasm"
YIELD_REGISTRY_ID=$(deploy_contract "$YIELD_REGISTRY_WASM")
echo "Yield Registry ID: $YIELD_REGISTRY_ID"

# 3. Deploy Vault
VAULT_WASM="$WASM_DIR/vault_contract.wasm"
VAULT_ID=$(deploy_contract "$VAULT_WASM")
echo "Vault ID: $VAULT_ID"

# Update contracts.toml (Simple sed for demonstration, better to use a TOML parser)
# Note: This is a fragile way to update TOML, but works for the requirements.
sed -i "s/vault = .*/vault = \"$VAULT_ID\"/" "$CONFIG_FILE"
sed -i "s/vault_token = .*/vault_token = \"$VAULT_TOKEN_ID\"/" "$CONFIG_FILE"
sed -i "s/yield_registry = .*/yield_registry = \"$YIELD_REGISTRY_ID\"/" "$CONFIG_FILE"

echo "Success! Contract IDs saved to $CONFIG_FILE"
Loading