{"id":19259307,"url":"https://github.com/hyperweb-io/cwsc","last_synced_at":"2025-04-21T16:30:50.087Z","repository":{"id":159294898,"uuid":"627851162","full_name":"hyperweb-io/cwsc","owner":"hyperweb-io","description":"Reference compiler implementation for CWScript","archived":false,"fork":false,"pushed_at":"2024-01-19T07:35:53.000Z","size":6429,"stargazers_count":8,"open_issues_count":7,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-01T14:21:22.524Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://cosmology.zone/products/cwscript","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hyperweb-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-14T10:42:11.000Z","updated_at":"2025-01-18T00:48:07.000Z","dependencies_parsed_at":"2024-01-19T09:39:24.685Z","dependency_job_id":null,"html_url":"https://github.com/hyperweb-io/cwsc","commit_stats":null,"previous_names":["cosmology-tech/cwsc","hyperweb-io/cwsc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperweb-io%2Fcwsc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperweb-io%2Fcwsc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperweb-io%2Fcwsc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperweb-io%2Fcwsc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperweb-io","download_url":"https://codeload.github.com/hyperweb-io/cwsc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250090694,"owners_count":21373234,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T19:16:04.894Z","updated_at":"2025-04-21T16:30:49.022Z","avatar_url":"https://github.com/hyperweb-io.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `cwsc`: CWScript Compiler\n\nCWScript is a high-level programming language designed for writing smart contracts on the CosmWasm platform. It is focused on simplifying the process of creating smart contracts while maintaining compatibility with Rust and CosmWasm programming patterns. CWScript enforces a more constrained framework for writing smart contracts, allowing developers to build on a well-defined domain. This approach aims to streamline code organization, composability patterns, and the overall development experience.\n\ncwsc is written in TypeScript and requires Node.js v16 or later.\n\n\u003c!-- TOC --\u003e\n* [`cwsc`: CWScript Compiler](#cwsc-cwscript-compiler)\n  * [Features](#features)\n  * [Installation](#installation)\n  * [Usage](#usage)\n  * [Examples](#examples)\n    * [Hello World](#hello-world)\n    * [Simple Token Contract](#simple-token-contract)\n    * [Proxy Contract](#proxy-contract)\n    * [AtomicOrderExample (Injective Protocol)](#atomicorderexample-injective-protocol)\n  * [License](#license)\n  * [Copyright](#copyright)\n\u003c!-- TOC --\u003e\n\n## Features\n- Simplified syntax, reducing syntactic noise and enhancing readability\n- High-level translation to idiomatic CosmWasm Rust patterns\n- Tooling-first approach, built for seamless integration with existing and new development tools\n- Designed to be extensible and compatible with Rust\n- Comprehensive documentation to guide you through the CWScript journey\n\n\n## Installation\n**Initial release coming soon. Announcement will be made on official channels.**\n##\n## Usage\nPlease refer to the official documentation for a complete guide on how to use CWScript and the cwsc compiler. Discover how to create, compile, and deploy smart contracts, and learn about the unique features of CWScript that simplify development and increase productivity.\n\n## Examples\n\n### Hello World\n\n```rs\ncontract HelloWorld {\n    state {\n        greeting: String\n    }\n\n    #instantiate(init_greeting: String) {\n        $state.greeting = init_greeting\n    }\n\n    exec #update_greeting(new_greeting: String) {\n        $state.greeting = new_greeting\n    }\n\n    query #get_greeting() -\u003e String {\n        return $state.greeting\n    }\n}\n```\n\n### Simple Token Contract\n\n```rs\ncontract MyToken {\n    state {\n        total_supply: Uint128,\n        balances[Address]: Uint128 = 0\n    }\n\n    #instantiate(initial_supply: Uint128) {\n        let creator = $info.sender\n        $state.total_supply = initial_supply\n        $state.balances[creator] = initial_supply\n    }\n\n    exec #transfer(to: Address, amount: Uint128) {\n        let sender = $info.sender\n        let sender_balance = $state.balances[sender] ?? Uint128(0)\n\n        assert!(sender_balance \u003e= amount, \"Insufficient balance\")\n\n        $state.balances[sender] = sender_balance - amount\n        $state.balances[to] += amount\n    }\n\n    query #balance_of(address: Address) -\u003e Uint128 {\n        return $state.balances[address] ?? Uint128(0)\n    }\n\n    query #total_supply() -\u003e Uint128 {\n        return $state.total_supply\n    }\n}\n```\n\n### Proxy Contract\n\n```rs\nimport { CW20 } from \"standards/cw20\"\n\ncontract ProxyContract {\n    state {\n        target_token: Address\n    }\n\n    #instantiate(target_token_address: Address) {\n        $state.target_token = target_token_address\n    }\n\n    exec #transfer_proxy(to: Address, amount: Uint128) {\n        let sender = $info.sender\n\n        // Call the transfer method of the target CW20 contract\n        exec! CW20($state.target_token).#transfer(to, amount)\n    }\n\n    query #balance_of_proxy(address: Address) -\u003e Uint128 {\n        // Call the balance_of method of the target CW20 contract\n        return query! CW20($state.target_token).#balance_of(address)\n    }\n}\n```\n\n### AtomicOrderExample (Injective Protocol)\n\n```rs\nimport { SubaccountId, MarketId } from \"injective/types\"\nimport { FPDecimal } from \"injective/math\"\nimport { CW2 } from \"standards/cw2\"\n\nconst CONTRACT_NAME = \"crates.io:atomic-order-example\"\nconst CONTRACT_VERSION = \"0.0.1\"\n\ncontract AtomicOrderExample extends CW2 {\n\n  state {\n    config: struct ContractConfigState {\n      market_id: MarketId,\n      owner: Address,\n      contract_subaccount_id: SubaccountId,\n      base_denom: String,\n      quote_denom: String\n    }\n    swap_operation_state: struct SwapCacheState {\n      sender_address: String,\n      deposited_amount: Coin\n    }\n  }\n\n  #instantiate(\n    market_id: MarketId\n  ) {\n\n    let market = try {\n      query! Exchange.#market(market_id)\n    } else fail! \"Market with id: {market_id} not found\"\n\n    let config = ContractConfigState {\n      market_id,\n      base_denom: market.base_denom,\n      quote_denom: market.quote_denom,\n      owner: $info.sender,\n      contract_subaccount_id: SubaccountId($env.contract.address, 0),\n    }\n\n    CW2.set_contract_version!($, CONTRACT_NAME, CONTRACT_VERSION)\n\n    // we've changed it to \"config\"\n    $state.config = config\n    emit event(method=\"instantiate\", owner=$info.sender) // anonymous event\n  }\n\n  reply.success handle_atomic_order() {\n    let dec_scale_factor = FPDecimal(1000000000000000000)\n    let order_response = Exchange.#create_spot_market_order::parse_response!($data)\n\n    let trade_data = order_response.results ?? fail! \"No trade data in order response\"\n    let quantity = FPDecimal!(trade_data.quantity)\n    let price = FPDecimal!(trade_data.price)\n    let fee = FPDecimal!(trade_data.fee)\n\n    let { config, cache } = $state\n    let contract_address = $env.contract.address\n    let subaccount_id = config.contract_subaccount_id\n    let cache = $state.cache\n    let purchased_coins = coin(quantity, config.base_denom)\n    let pair = quantity * price + fee\n    let leftover = cache.deposited_amount.amount - paid\n\n\n    exec! Exchange.#withdraw(contract_address, subaccount_id, purchased_coins)\n    exec! Exchange.#withdraw(contract_address, subaccount_id, leftover_coins)\n    exec! Bank.#send(cache.sender_address, [purchased_coins, leftover_coins])\n  }\n\n  exec #swap_spot(quantity: FPDecimal, price: FPDecimal) {\n    let { config } = $state\n    let contract = $env.contract.address\n    let subaccount_id = config.contract_subaccount_id\n    let min_deposit = price quantity\n\n    if $info.funds.is_empty() {\n      fail! \"No funds deposited!\"\n    }\n\n    let message_deposit = FPDecimal!($info.funds[0].amount)\n\n    if message_deposit \u003c min_deposit {\n      fail! \"Deposit: {message_deposit} below min_deposit: {min_deposit}\"\n    }\n\n    let order = SpotOrder(\n      price, quantity, OrderType.#BuyAtomic, config.market_id, subaccount_id, contract\n    )\n\n    let coins = $info.funds[0]\n\n    $state.swap_operation_state = SwapCacheState($info.sender, coins)\n\n    exec! Exchange.#deposit(contract, subaccount_id, coins)\n\n    @reply.success(handle_atomic_order)\n    exec! Exchange.create_spot_market_order(contract, order)\n  }\n\n}\n```\n\n## Related\n\nCheckout these related projects:\n\n* [@cosmology/telescope](https://github.com/cosmology-tech/telescope) Your Frontend Companion for Building with TypeScript with Cosmos SDK Modules.\n* [@cosmwasm/ts-codegen](https://github.com/CosmWasm/ts-codegen) Convert your CosmWasm smart contracts into dev-friendly TypeScript classes.\n* [chain-registry](https://github.com/cosmology-tech/chain-registry) Everything from token symbols, logos, and IBC denominations for all assets you want to support in your application.\n* [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit) Experience the convenience of connecting with a variety of web3 wallets through a single, streamlined interface.\n* [create-cosmos-app](https://github.com/cosmology-tech/create-cosmos-app) Set up a modern Cosmos app by running one command.\n* [interchain-ui](https://github.com/cosmology-tech/interchain-ui) The Interchain Design System, empowering developers with a flexible, easy-to-use UI kit.\n* [starship](https://github.com/cosmology-tech/starship) Unified Testing and Development for the Interchain.\n\n## Credits\n\n🛠 Built by Cosmology — if you like our tools, please consider delegating to [our validator ⚛️](https://cosmology.zone/validator)\n\n\n## Disclaimer\n\nAS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.\n\nNo developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.\n\n## License\nCWScript, cwsc, and its bundled toolchain are licensed under the MIT License.\n\n## Copyright\n\nCopyright © 2021-2023 Web, Inc.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperweb-io%2Fcwsc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperweb-io%2Fcwsc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperweb-io%2Fcwsc/lists"}