This workspace contains CosmWasm smart contracts for managing Akash SDL (Stack Definition Language) templates with variable substitution and default value management.
A CosmWasm contract that stores SDL templates as JSON with configurable variable defaults. Features include:
- Template Storage: Store SDL templates as JSON with validation
- Variable Validation: Ensures all template variables have corresponding defaults
- Variable Management: Define and update default values for template variables
- Variable Substitution: Render SDL templates with custom or default variable values
- Factory Pattern: Instantiate new contract instances from the same code ID
- Access Control: Admin-based permissions for template updates
The easiest way to build and test contracts is using the just task runner from the project root:
# Build optimized contracts (production-ready)
just contracts-optimize
# Or use the short alias
just cw
# Test all contracts
just contracts-test
# Or use the short alias
just ct
# Check contracts (faster than build)
just contracts-check
# Generate JSON schemas
just contracts-schema
# Clean contract artifacts
just contracts-cleanBuild all contracts in debug mode:
cd contracts
cargo build --workspaceBuild a specific contract:
cd contracts/cw-sdl
cargo build --release --target wasm32-unknown-wasm32Run tests for all contracts:
just contracts-test
# Or manually:
cd contracts && cargo test --workspaceRun tests for a specific contract:
cd contracts/cw-sdl
cargo testTo produce optimized WASM artifacts ready for deployment, use the just command:
just contracts-optimizeThis automatically detects your platform (ARM64 or x86_64) and runs the appropriate CosmWasm optimizer Docker image. Optimized .wasm files will be in contracts/artifacts/.
Manual optimization:
cd contracts
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/optimizer:0.16.0Generate JSON schemas for contract messages:
cd contracts/cw-sdl
cargo schemaSchemas will be output to schema/ directory.
Instantiate a new SDL template contract:
{
"sdl_template": "{\"version\": \"2.0\", ...}",
"variable_defaults": {
"CPU": "1.0",
"MEMORY": "512Mi",
"STORAGE": "1Gi"
},
"label": "nginx-template",
"admin": "akash1..."
}{
"update_template": {
"sdl_template": "{\"version\": \"2.0\", ...}"
}
}{
"update_defaults": {
"variable_defaults": {
"CPU": "2.0",
"MEMORY": "1Gi"
}
}
}{
"update_single_default": {
"key": "CPU",
"value": "4.0"
}
}{
"instantiate_new": {
"instantiate_msg": {
"sdl_template": "{...}",
"variable_defaults": {...},
"label": "new-template",
"admin": "akash1..."
},
"label": "factory-instantiated-template"
}
}{
"get_template": {}
}Returns:
{
"sdl_template": "{...}",
"template_json": {...}
}{
"get_defaults": {}
}Returns:
{
"defaults": {
"CPU": "1.0",
"MEMORY": "512Mi"
}
}{
"get_default": {
"key": "CPU"
}
}Returns:
{
"key": "CPU",
"value": "1.0"
}{
"render_sdl": {
"variables": {
"CPU": "2.0"
}
}
}Returns:
{
"rendered_sdl": "{...}",
"used_variables": {
"CPU": "2.0",
"MEMORY": "512Mi"
}
}If variables is omitted, all defaults will be used.
{
"get_info": {}
}Returns:
{
"label": "nginx-template",
"admin": "akash1...",
"code_id": 123
}The SDL template contracts are designed to integrate with the Ergors orchestration system:
- Contract Discovery: Ergors nodes query Cnidarium storage for contract addresses using label mapping
- Template Loading: Load SDL templates from contracts with
GetTemplatequery - Variable Configuration: Retrieve defaults with
GetDefaultsand optionally prompt users - SDL Rendering: Use
RenderSdlto generate final SDL with custom or default values - Deployment: Deploy rendered SDL to Akash Network
Variables in SDL templates use the format ${VARIABLE_NAME}. All variables must have corresponding defaults defined at instantiation. Example:
{
"profiles": {
"compute": {
"web": {
"resources": {
"cpu": {
"units": "${CPU}"
},
"memory": {
"size": "${MEMORY}"
}
}
}
}
}
}When rendered with defaults {"CPU": "1.0", "MEMORY": "512Mi"}, produces:
{
"profiles": {
"compute": {
"web": {
"resources": {
"cpu": {
"units": "1.0"
},
"memory": {
"size": "512Mi"
}
}
}
}
}
}This project is part of the Ergors ecosystem.