Skip to content

Commit

Permalink
Merge pull request #144 from freespek/th/case-study-xycloans
Browse files Browse the repository at this point in the history
Add the Xycloans case study
  • Loading branch information
thpani authored Oct 23, 2024
2 parents 7f8e9d7 + ce62543 commit 6652035
Show file tree
Hide file tree
Showing 14 changed files with 257 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "ContractExamples/soroban-examples"]
path = ContractExamples/soroban-examples
url = https://github.com/stellar/soroban-examples
[submodule "ContractExamples/xycloans"]
path = ContractExamples/xycloans
url = https://github.com/xycloo/xycloans.git
71 changes: 71 additions & 0 deletions ContractExamples/scripts/xycloans-populate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash
#
# Deploy the Xycloans contracts and populate their state with data.
#
# Thomas Pani, 2024
#
# @license
# [Apache-2.0](https://github.com/freespek/solarkraft/blob/main/LICENSE)


set -e

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

cd ${dir}/../xycloans

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

ADMIN=admin
soroban keys address $ADMIN || (echo "add the account $ADMIN via soroban keys generate"; exit 1)

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

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

XLM_ADDRESS=CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC
BORROW_AMOUNT=1000

set -x

soroban contract build

soroban contract deploy --wasm target/wasm32-unknown-unknown/release/xycloans_factory.wasm \
--source $ADMIN --network $NET | tee >.xycloans_factory.id
soroban contract deploy --wasm target/wasm32-unknown-unknown/release/simple.wasm \
--source $ADMIN --network $NET | tee >.xycloans_simple.id
soroban contract install --wasm target/wasm32-unknown-unknown/release/xycloans_pool.wasm \
--source $ADMIN --network $NET | tee >.xycloans_pool.wasmhash

# initialize the factory contract and deploy a pool
soroban contract invoke --id $(cat .xycloans_factory.id) --source $ADMIN --network $NET \
-- initialize --pool_hash $(cat .xycloans_pool.wasmhash) --admin $ADMIN
soroban contract invoke --id $(cat .xycloans_factory.id) --source $ADMIN --network $NET \
-- deploy_pool --token_address $XLM_ADDRESS --salt efefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefef | tr -d '"' | tee >.xycloans_pool.id

# initialize the simple receiver contract and transfer it some tokens so it can pay fees
soroban contract invoke --id $(cat .xycloans_simple.id) --source $ADMIN --network $NET \
-- init --token_id $XLM_ADDRESS --fl_address $(cat .xycloans_pool.id) --amount $BORROW_AMOUNT
soroban contract invoke --id $XLM_ADDRESS --source $ADMIN --network $NET \
-- transfer --from $ADMIN --to $(cat .xycloans_simple.id) --amount 10000

# deposit some tokens into the pool
soroban contract invoke --id $(cat .xycloans_pool.id) --source $ALICE --network $NET \
-- deposit --from $ALICE --amount 1000
soroban contract invoke --id $(cat .xycloans_pool.id) --source $BOB --network $NET \
-- deposit --from $BOB --amount 1

# borrow some tokens from the pool
soroban contract invoke --id $(cat .xycloans_pool.id) --source $ADMIN --network $NET \
-- borrow --receiver_id $(cat .xycloans_simple.id) --amount $BORROW_AMOUNT

# update the fee rewards and withdraw the matured rewards
soroban contract invoke --id $(cat .xycloans_pool.id) --source $BOB --network $NET \
-- update_fee_rewards --addr $BOB
soroban contract invoke --id $(cat .xycloans_pool.id) --source $BOB --network $NET \
-- withdraw_matured --addr $BOB

cd ${dir}
1 change: 1 addition & 0 deletions ContractExamples/xycloans
Submodule xycloans added at e06637
3 changes: 2 additions & 1 deletion solarkraft/.prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
test/e2e/verify_js_example.ts
test/e2e/verify_js_example_timelock.ts
test/e2e/verify_js_example_xycloans.ts
12 changes: 12 additions & 0 deletions solarkraft/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions solarkraft/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@sweet-monads/maybe": "^3.3.1",
"@types/urijs": "^1.19.25",
"axios": "^1.7.5",
"big-round": "^2.0.0",
"chalk": "^5.3.0",
"glob": "^10.3.15",
"immutable": "^5.0.0-beta.5",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 28 additions & 4 deletions solarkraft/test/e2e/verify_js_example.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* E2E tests for the JavaScript / TypeScript monitor in
* `test/e2e/verify_js_example.ts`.
* E2E tests for the example TypeScript monitors in
* `test/e2e/verify_js_example_*.ts`.
*
* @author Thomas Pani, 2024
*/
Expand All @@ -10,9 +10,9 @@ import { describe, it } from 'mocha'
import { spawn } from 'nexpect'

describe('verify JavaScript monitor', () => {
it('reports success on `verify_js_example.ts`', function (done) {
it('reports success on `verify_js_example_timelock.ts`', function (done) {
this.timeout(50_000)
spawn('node dist/test/e2e/verify_js_example.js')
spawn('node dist/test/e2e/verify_js_example_timelock.js')
.wait(
'Verifying deposit (successful tx e10a55db588f097f8ce9e214ae717c5ecbd6d13d5a2fb3142c71c1866c9ca537)...'
)
Expand All @@ -30,4 +30,28 @@ describe('verify JavaScript monitor', () => {
.expect('[OK]: tx reverted as expected by reverts_if conditions')
.run(done)
})

it('reports error on `verify_js_example_xycloans.ts`', function (done) {
this.timeout(50_000)
spawn('node dist/test/e2e/verify_js_example_xycloans.js', {
stream: 'all',
})
.wait(
'Verifying deposit (successful tx 49ce70a0fe73f9b815f50dbe13403608242cec0770ac32eb24d1a425e39467be)...'
)
.expect('[OK]: all succeeds_with conditions hold')
.wait(
'Verifying deposit (successful tx af8d698431a4354bbe74517d741bbb278180eae2c6907ddc0abf5fcacd8b938b)...'
)
.expect('[OK]: all succeeds_with conditions hold')
.wait(
'Verifying borrow (successful tx 20a4726ab7291e00bfaad767a034844ffffd25f73882b5288da5486e3cc01973)...'
)
.expect('[OK]: all succeeds_with conditions hold')
.wait(
'Verifying update_fee_rewards (successful tx e5064617326554c02de8edd6628f1e1951903497698b3f1f5f0b00e03b2a16b6)...'
)
.expect('[Error]: some succeeds_with conditions do not hold')
.run(done)
})
})
File renamed without changes.
Loading

0 comments on commit 6652035

Please sign in to comment.