Skip to content

Commit

Permalink
Add launch scripts (#614)
Browse files Browse the repository at this point in the history
* Add launch scripts

* format code & use only one .gitignore

* add start script

* remove asset-setup.sh

* simplify loop

* use legacy node_modules linker

* add missing amm-bench target

* Resolve comments

* Update script for log once

* Fix decimal issue

* Update init assets

* ignore yarn error log

* update editorcofnig

* run test also for benchmark

* activate try-runtime for pallet-assets

* check also wasm build

* remove genesis markets & fix ratio decimal

Co-authored-by: Alan WANG <[email protected]>
Co-authored-by: Cheng JIANG <[email protected]>
  • Loading branch information
3 people authored Sep 19, 2021
1 parent 207752a commit ef1b874
Show file tree
Hide file tree
Showing 16 changed files with 3,705 additions and 129 deletions.
13 changes: 7 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
root = true
[*.rs]
[*]
indent_style=tab
indent_size=2
indent_size=tab
tab_width=4
end_of_line=lf
charset=utf-8
trim_trailing_whitespace=true
max_line_length=100
insert_final_newline=true

[*.md]
max_line_length=80
indent_style=space
indent_size=2

[*.yml]
indent_style=space
indent_size=2
Expand All @@ -20,7 +25,3 @@ indent_style=space
indent_size=2
tab_width=8
end_of_line=lf

[*.json]
indent_style=tab
tab_width=2
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
- name: Check Build
run: |
make check
make check-wasm
- name: Check Clippy Warnings
run: |
Expand Down
22 changes: 18 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# The cache for chain data in container
.local

# cargo-remote configuration
.cargo-remote.toml

local-test

# archives
*.tar.xz
*.tar.gz
*.tgz
Expand All @@ -31,15 +31,29 @@ dist/
*.log
*-local*.json

# chain db
chains/
db/
local-test/

# secrets
**/keystore*

# parachain launch output directory
output/

config.prod.yml

# snapshot generated by try-runtime subcommand
snapshot.bin

# vimspector debugger config
.vimspector.json

# Setting for non zero-installs (https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored)
**/.yarn/*
**/.pnp.*
**/node_modules/
**/yarn-error.log
!**/.yarn/releases
!**/.yarn/plugins
!**/.yarn/sdks
!**/.yarn/versions
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ init: submodules
git config advice.ignoredHook false
git config core.hooksPath .githooks
rustup target add wasm32-unknown-unknown
cd launch && yarn

.PHONY: submodules
submodules:
Expand All @@ -25,16 +26,24 @@ build:
check:
SKIP_WASM_BUILD= cargo check --all-targets --features runtime-benchmarks --features try-runtime

.PHONY: check-wasm
check-wasm:
cargo check -p vanilla-runtime -p parallel-runtime -p heiko-runtime

.PHONY: test
test:
SKIP_WASM_BUILD= cargo test --workspace --exclude parallel --exclude parallel-runtime --exclude vanilla-runtime --exclude heiko-runtime -- --nocapture
SKIP_WASM_BUILD= cargo test --workspace --features runtime-benchmarks --exclude parallel --exclude parallel-runtime --exclude vanilla-runtime --exclude heiko-runtime -- --nocapture

.PHONY: bench
bench: bench-loans bench-liquid-staking
bench: bench-loans bench-liquid-staking bench-amm

.PHONY: bench-loans
bench-loans:
cargo run --features runtime-benchmarks -- benchmark --chain=$(CHAIN) --execution=wasm --wasm-execution=compiled --pallet=pallet-loans --extrinsic='*' --steps=50 --repeat=20 --heap-pages=4096 --template=./.maintain/frame-weight-template.hbs --output=./pallets/loans/src/weights.rs
cargo run --release --features runtime-benchmarks -- benchmark --chain=$(CHAIN) --execution=wasm --wasm-execution=compiled --pallet=pallet-loans --extrinsic='*' --steps=50 --repeat=20 --heap-pages=4096 --template=./.maintain/frame-weight-template.hbs --output=./pallets/loans/src/weights.rs

.PHONY: bench-amm
bench-amm:
cargo run --release --features runtime-benchmarks -- benchmark --chain=$(CHAIN) --execution=wasm --wasm-execution=compiled --pallet=pallet-amm --extrinsic='*' --steps=50 --repeat=20 --heap-pages=4096 --template=./.maintain/frame-weight-template.hbs --output=./pallets/amm/src/weights.rs

.PHONY: bench-liquid-staking
bench-liquid-staking:
Expand Down Expand Up @@ -70,6 +79,7 @@ launch: shutdown
docker image pull parallelfinance/parallel-dapp:latest
docker image pull parallelfinance/stake-client:latest
parachain-launch generate $(LAUNCH_CONFIG) && (cp -r keystore* output || true) && cp docker-compose.override.yml output && docker-compose -f output/docker-compose.yml -f output/docker-compose.override.yml up -d --build
cd launch && yarn start

.PHONY: logs
logs:
Expand Down
631 changes: 631 additions & 0 deletions launch/.yarn/releases/yarn-rc.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions launch/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-rc.js
66 changes: 66 additions & 0 deletions launch/assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"liquidAsset": 1000,
"stakingAsset": 100,
"assets": [
{
"name": "Kusama",
"symbol": "KSM",
"assetId": 100,
"decimal": 12,
"marketOption": {
"closeFactor": 50e4,
"collateralFactor": 50e4,
"reserveFactor": 15e4,
"liquidateIncentive": 110e16,
"rateModel": {
"jumpModel": {
"baseRate": 2e16,
"jumpRate": 10e16,
"fullRate": 32e16,
"jumpUtilization": 8e5
}
}
}
},
{
"name": "Parallel Kusama",
"symbol": "XKSM",
"assetId": 1000,
"decimal": 12,
"marketOption": {
"closeFactor": 50e4,
"collateralFactor": 50e4,
"reserveFactor": 15e4,
"liquidateIncentive": 110e16,
"rateModel": {
"jumpModel": {
"baseRate": 2e16,
"jumpRate": 10e16,
"fullRate": 32e16,
"jumpUtilization": 8e5
}
}
}
},
{
"name": "Tether Dollar",
"symbol": "USDT",
"assetId": 102,
"decimal": 6,
"marketOption": {
"closeFactor": 50e4,
"collateralFactor": 50e4,
"reserveFactor": 15e4,
"liquidateIncentive": 110e16,
"rateModel": {
"jumpModel": {
"baseRate": 2e16,
"jumpRate": 10e16,
"fullRate": 32e16,
"jumpUtilization": 8e5
}
}
}
}
]
}
61 changes: 61 additions & 0 deletions launch/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {options} from '@parallel-finance/api'
import {ApiPromise, Keyring, WsProvider} from '@polkadot/api'
import {assets, liquidAsset, stakingAsset} from './assets.json'

function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}

async function main() {

const api = await ApiPromise.create(
options({
provider: new WsProvider('ws://localhost:9947'),
})
)

const chainHeight = async () => {
const {
block: {
header: {number: height},
},
} = await api.rpc.chain.getBlock()
return height.toNumber()
}

console.log("Wait for block producing")
do await sleep(1000)
while (!(await chainHeight()))

const keyring = new Keyring({type: 'sr25519', ss58Format: 110})
const signer = keyring.addFromUri('//Dave')

let call = []

for (const {name, symbol, assetId, decimal, marketOption} of assets) {
console.log(`Create ${name}(${symbol}) asset.`)
call.push(
api.tx.sudo.sudo(api.tx.assets.forceCreate(assetId, signer.address, true, 1)),
api.tx.sudo.sudo(
api.tx.assets.forceSetMetadata(assetId, name, symbol, decimal, false)
),
api.tx.sudo.sudo(
api.tx.loans.addMarket(
assetId,
api.createType('Market', marketOption)
)
)
)
}

call.push(
api.tx.sudo.sudo(api.tx.liquidStaking.setLiquidCurrency(liquidAsset)),
api.tx.sudo.sudo(api.tx.liquidStaking.setStakingCurrency(stakingAsset))
)

console.log('Submit batches.')
await api.tx.utility.batchAll(call).signAndSend(signer)
process.exit(0)
}

main()
19 changes: 19 additions & 0 deletions launch/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "launch",
"version": "1.0.0",
"main": "index.ts",
"scripts": {
"start": "ts-node index.ts"
},
"devDependencies": {
"@types/node": "^16.7.10",
"ts-node": "^10.2.1",
"typescript": "^4.4.3"
},
"dependencies": {
"@parallel-finance/api": "^1.1.3-2",
"@polkadot/api": "^5.6.2-5",
"@polkadot/rpc-core": "^5.6.2-5",
"@polkadot/types": "^5.6.2-5"
}
}
5 changes: 5 additions & 0 deletions launch/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"resolveJsonModule": true
}
}
Loading

0 comments on commit ef1b874

Please sign in to comment.