Skip to content

Commit

Permalink
Merge pull request #150 from freespek/igor/contract-setup
Browse files Browse the repository at this point in the history
fixing the CI + workflow for deploying contracts to testnet
  • Loading branch information
konnov authored Dec 5, 2024
2 parents 8a232b3 + 8a19d02 commit 2d55c7a
Show file tree
Hide file tree
Showing 24 changed files with 518 additions and 413 deletions.
34 changes: 14 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,23 @@ jobs:
toolchain:
- stable
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: rustup target add wasm32-unknown-unknown
- uses: stellar/binaries@v22
# see: https://github.com/stellar/soroban-examples/blob/main/.github/workflows/rust.yml
- uses: stellar/actions/rust-cache@main
# pin the rust version: https://github.com/stellar/rs-soroban-sdk/pull/1353
- run: |
rustup default 1.81.0
rustup update
- run: cargo version
- uses: stellar/stellar-cli@main
with:
name: soroban-cli
version: '20.0.0-rc.4.1'
# version 21 is not available in stellar/binaries yet
#version: '21.0.0-preview.1'
version: 22.0.0

- run: stellar --version

- name: build
run: cd ContractExamples && cargo build --verbose --workspace --exclude "soroban-timelock-contract" --exclude "soroban-token-contract"
- name: unit tests
run: cd ContractExamples && cargo test --verbose --workspace --exclude "soroban-timelock-contract" --exclude "soroban-token-contract"

# v21 is not available in stellar/binaries yet
#- name: populating Setter
# run: |
# soroban network add \
# --global testnet \
# --rpc-url https://soroban-testnet.stellar.org:443 \
# --network-passphrase "Test SDF Network ; September 2015"
# soroban keys generate --global alice --network testnet
# cd ContractExamples
# ./scripts/setter-populate.sh
run: cd ContractExamples && cargo test --verbose --workspace --exclude "soroban-timelock-contract" --exclude "soroban-token-contract"
62 changes: 62 additions & 0 deletions .github/workflows/testnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Deployment to testnet

on:
workflow_dispatch:
schedule:
# This cron expression triggers the workflow at 8:00 UTC every day
- cron: "8 0 * * *"
# uncomment to debug in a PR
#pull_request:

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
# see: https://github.com/stellar/soroban-examples/blob/main/.github/workflows/rust.yml
- uses: stellar/actions/rust-cache@main
# pin the rust version: https://github.com/stellar/rs-soroban-sdk/pull/1353
- run: |
rustup default 1.81.0
rustup update
- run: cargo version
- uses: stellar/stellar-cli@main
with:
version: 22.0.0

- run: stellar --version

- name: Generate Soroban keys
run: |
stellar keys generate --global alice --network testnet --fund
stellar keys generate --global bob --network testnet --fund
stellar keys generate --global admin --network testnet --fund
- name: Build contract examples
run: |
cd ContractExamples
rustup target add wasm32-unknown-unknown
# it's important to disable reference types, otherwise we get deployment errors
RUSTFLAGS="-C target-feature=-reference-types" cargo build --target wasm32-unknown-unknown --release
- name: Deploy alert
run: |
cd ContractExamples
./scripts/alert-deploy.sh
- name: Deploy setter
run: |
cd ContractExamples
./scripts/setter-populate.sh
- name: Deploy timelock
run: |
cd ContractExamples
./scripts/prepare-timelock.sh
- name: Deploy xycloans
run: |
cd ContractExamples
./scripts/xycloans-populate.sh
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
[submodule "ContractExamples/xycloans"]
path = ContractExamples/xycloans
url = https://github.com/xycloo/xycloans.git
branch = b26e0124ab0b84c1be25c636492671f106653f09
8 changes: 6 additions & 2 deletions ContractExamples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ members = [
"soroban-examples/timelock/"
]

[workspace.package]
version = "22.0.0-rc.3.1"
edition = "2021"

[workspace.dependencies]
soroban-sdk = "21.6.0"
soroban-sdk = { version = "22.0.0-rc.3.1" }

[profile.release]
opt-level = "z"
Expand All @@ -22,4 +26,4 @@ lto = true
# For more information about this profile see https://soroban.stellar.org/docs/basic-tutorials/logging#cargotoml-profile
[profile.release-with-logs]
inherits = "release"
debug-assertions = true
debug-assertions = true
2 changes: 1 addition & 1 deletion ContractExamples/contracts/alert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ doctest = false
soroban-sdk = { workspace = true }

[dev-dependencies]
soroban-sdk = { version = "21.6.0", features = ["testutils"] }
soroban-sdk = { version = "22.0.0-rc.3.1", features = ["testutils"] }
2 changes: 1 addition & 1 deletion ContractExamples/contracts/megacontract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ doctest = false
soroban-sdk = { workspace = true }

[dev-dependencies]
soroban-sdk = { version = "21.6.0", features = ["testutils"] }
soroban-sdk = { version = "22.0.0-rc.3.1", features = ["testutils"] }
2 changes: 1 addition & 1 deletion ContractExamples/contracts/setter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ doctest = false
soroban-sdk = { workspace = true }

[dev-dependencies]
soroban-sdk = { version = "21.6.0", features = ["testutils"] }
soroban-sdk = { version = "22.0.0-rc.3.1", features = ["testutils"] }
30 changes: 30 additions & 0 deletions ContractExamples/patches/xycloans.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/Cargo.toml b/Cargo.toml
index e3a7104..b18672f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,11 +3,11 @@ resolver = "2"
members = [
#"flash-loan",
#"receiver-standard",
+ "pool",
+ "factory",
"examples/simple",
#"vault",
#"vault-interface",
- "factory",
- "pool"
]

[profile.release-with-logs]
@@ -26,8 +26,8 @@ lto = true


[workspace.dependencies.soroban-sdk]
-version = "20.0.0"
+version = "22.0.0-rc.3"


[workspace.dependencies.fixed-point-math]
-version = "0.0.2"
\ No newline at end of file
+version = "0.0.2"
13 changes: 13 additions & 0 deletions ContractExamples/patches/xycloans2.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/examples/simple/src/lib.rs b/examples/simple/src/lib.rs
index 021a924..c75abb1 100644
--- a/examples/simple/src/lib.rs
+++ b/examples/simple/src/lib.rs
@@ -48,7 +48,7 @@ impl FlashLoanReceiver for FlashLoanReceiverContract {
.get::<DataKey, i128>(&DataKey::Amount)
.unwrap();

- let total_amount = borrowed + compute_fee(&borrowed);
+ let total_amount = borrowed + compute_fee(&borrowed) + 1;

let flash_loan = e
.storage()
10 changes: 5 additions & 5 deletions ContractExamples/scripts/alert-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
set -e

dir=$(cd `dirname $0`; pwd -P)

cd ${dir}/..

NET=testnet
(soroban network ls | grep -q $NET) || (echo "add testnet via soroban network"; exit 1)
(stellar network ls | grep -q $NET) || (echo "add testnet via stellar network"; exit 1)

ACCOUNT=alice
soroban keys address $ACCOUNT || (echo "add the account $ACCOUNT via soroban keys generate"; exit 1)
stellar keys address $ACCOUNT || (echo "add the account $ACCOUNT via stellar keys generate"; exit 1)


set -x

soroban contract build
soroban contract deploy --wasm target/wasm32-unknown-unknown/release/alert.wasm \
./scripts/build.sh

stellar contract deploy --wasm target/wasm32-unknown-unknown/release/alert.wasm \
--source $ACCOUNT --network $NET
22 changes: 22 additions & 0 deletions ContractExamples/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

# see: https://github.com/stellar/rs-soroban-sdk/pull/1353
rustc --version | grep 1.81.0 || (echo "Run: rustup default 1.81.0"; exit 1)

dir=$(cd `dirname $0`; pwd -P)
cd ${dir}/..

# build our contracts and soroban-examples
stellar contract build

# build xycloans
cd ${dir}/../xycloans
patch --forward -p1 <../patches/xycloans.diff || (echo "patch already applied?")
patch --forward -p1 <../patches/xycloans2.diff || (echo "patch already applied?")

stellar contract build

cd ${dir}

# When using rust over 1.81.0:
#RUSTFLAGS="-C target-feature=-reference-types" cargo build --target wasm32-unknown-unknown --release
58 changes: 32 additions & 26 deletions ContractExamples/scripts/prepare-timelock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,34 @@

set -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
dir=$(cd `dirname $0`; pwd -P)
cd ${dir}/..

ALICE=alice
soroban keys address $ALICE || (echo "add the account $ALICE via soroban keys generate"; exit 1)
stellar keys address $ALICE || (echo "add the account $ALICE via stellar keys generate"; exit 1)
BOB=bob
soroban keys address $BOB || (echo "add the account $BOB via soroban keys generate"; exit 1)
stellar keys address $BOB || (echo "add the account $BOB via stellar keys generate"; exit 1)

set -x
#set -x

TOKEN=$(
soroban contract deploy \
./scripts/build.sh

stellar contract deploy \
--source-account alice \
--network testnet \
--wasm $SCRIPT_DIR/../target/wasm32-unknown-unknown/release/soroban_token_contract.wasm
)
--wasm ./target/wasm32-unknown-unknown/release/soroban_token_contract.wasm \
-- --admin alice --decimal 18 --name TOK --symbol TOK \
| tee >.token.id

echo "Token contract ID: $TOKEN"
TOKEN=$(cat .token.id)
if [ -z "$TOKEN" ]; then
echo "Failed to deploy the token contract"
exit 1
fi

soroban contract invoke \
--id $TOKEN \
--source alice \
--network testnet \
-- \
initialize \
--admin alice \
--decimal 18 \
--name '"TOK"' \
--symbol '"TOK"'
echo "Token contract ID: $TOKEN"

soroban contract invoke \
stellar contract invoke \
--id $TOKEN \
--source alice \
--network testnet \
Expand All @@ -47,14 +45,22 @@ soroban contract invoke \
--to alice \
--amount 100

TIMELOCK=$(soroban contract deploy \
--wasm $SCRIPT_DIR/../target/wasm32-unknown-unknown/release/soroban_timelock_contract.wasm \
stellar contract deploy \
--wasm ./target/wasm32-unknown-unknown/release/soroban_timelock_contract.wasm \
--source alice \
--network testnet)
--network testnet \
| tee >.timelock.id

TIMELOCK=$(cat .timelock.id)

if [ -z "$TIMELOCK" ]; then
echo "Failed to deploy the timelock contract"
exit 1
fi

echo "Timelock contract ID: $TIMELOCK"

soroban contract invoke \
stellar contract invoke \
--id $TIMELOCK \
--source alice \
--network testnet \
Expand All @@ -63,10 +69,10 @@ soroban contract invoke \
--from alice \
--token $TOKEN \
--amount 1 \
--claimants "[\"$(soroban keys address bob)\"]"\
--claimants "[\"$(stellar keys address bob)\"]"\
--time_bound '{"kind": "After", "timestamp": 0}'

soroban contract invoke \
stellar contract invoke \
--id $TIMELOCK \
--source bob \
--network testnet \
Expand Down
Loading

0 comments on commit 2d55c7a

Please sign in to comment.