Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing the CI + workflow for deploying contracts to testnet #150

Merged
merged 55 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
d9a60a2
add a workflow for deploying contracts to testnet
konnov Nov 29, 2024
085457c
enable on PR for debugging
konnov Nov 29, 2024
029cc46
fix version
konnov Nov 29, 2024
8850be0
derive the workflow from the examples
konnov Nov 29, 2024
a90e70e
switch stellar-cli to main?
konnov Nov 29, 2024
678150b
build contracts and deploy alert
konnov Nov 29, 2024
0aa0ab7
rename soroban to stellar
konnov Nov 29, 2024
3c0c0cb
add timelock and setter
konnov Nov 29, 2024
36731c5
fix contract names
konnov Nov 29, 2024
239b666
fixes for 22.0.0
konnov Nov 29, 2024
9001e06
add wasm before building contracts
konnov Nov 29, 2024
60fa532
remove the offending flag?
konnov Nov 29, 2024
f8a7814
experiment with dependencies again
konnov Nov 29, 2024
bee3301
hmmm
konnov Nov 29, 2024
55418d0
again and again
konnov Nov 29, 2024
381e384
comment out reverting transactions
konnov Dec 2, 2024
6ac50e4
disable reference types
konnov Dec 2, 2024
2ec5fca
saving the hash into a file
konnov Dec 2, 2024
062251d
use salt
konnov Dec 2, 2024
fa78957
fix missing slashes
konnov Dec 2, 2024
8d666d2
pin the branch
konnov Dec 3, 2024
fce73fa
bump soroban examples to 21.6.0
konnov Dec 3, 2024
cd4e393
unpin soroban-examples
konnov Dec 3, 2024
a6439d8
call the constructor in timelock directly
konnov Dec 3, 2024
b4f019d
use the build script
konnov Dec 3, 2024
d884785
add the build script
konnov Dec 3, 2024
39eecdf
pin rust to 1.82.0
konnov Dec 3, 2024
d589d3a
add xycloans
konnov Dec 3, 2024
416cc29
generate the admin account
konnov Dec 3, 2024
7126afb
pin xycloans and build it from build.sh
konnov Dec 3, 2024
20eca18
call the build script of xycloans
konnov Dec 3, 2024
8559fd5
cd up
konnov Dec 3, 2024
2181f56
patch xycloans
konnov Dec 3, 2024
967b547
revert to 22.0.0
konnov Dec 3, 2024
59989a9
fix the order
konnov Dec 3, 2024
c04f268
downgrade to 1.81.0
konnov Dec 3, 2024
8a5fc2f
patch the sample contract
konnov Dec 4, 2024
4fea960
update the unit test setup
konnov Dec 4, 2024
1bfa6da
update sdk versions in the tests
konnov Dec 4, 2024
f26c902
update setter hash
konnov Dec 4, 2024
1839444
bump dependencies
konnov Dec 4, 2024
bd5f0c8
update after bumping stellar-sdk
konnov Dec 4, 2024
e5d7925
s/SorobanRpc/rpc
konnov Dec 4, 2024
9212678
change testnet to a cron job
konnov Dec 4, 2024
5cd6196
use RPC getTransaction since result_meta_xdr is gone from Horizon
konnov Dec 4, 2024
424b3bc
remove commented out code
konnov Dec 4, 2024
def3579
fix a typo
konnov Dec 4, 2024
41b17de
fixed after review
konnov Dec 5, 2024
6a64b8a
remove unnecessary profiles
konnov Dec 5, 2024
da6300d
uncomment a workflow
konnov Dec 5, 2024
0ab2f7e
remove @stellar/stellar-base
konnov Dec 5, 2024
1a75c78
use build.sh
konnov Dec 5, 2024
9ffb1bf
go back
konnov Dec 5, 2024
3faccf6
fix the path
konnov Dec 5, 2024
8a19d02
comment testnet.yml on pull_request
konnov Dec 5, 2024
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
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
Loading