A TypeScript Transpiler for Cosmos Protobufs ⚛️

Overview

Telescope 🔭

Babel for the Cosmos

A TypeScript Transpiler for Cosmos Protobufs

Quickstart

Follow the instructions below to kick off your Telescope module.

npm install -g @osmonauts/telescope

Generate

Use the generate command to create a new repository with the default proto files.

telescope generate
cd ./your-new-project
yarn 

Install

To install chain protobufs, run the install command.

telescope install

It's not necessary, but you may also specify specific packages, e.g.

telescope install @protobufs/osmosis

Transpile

To create the Typescript files, run the transpile command.

telescope transpile

You should now seem some .ts files generated in ./src. These are the real source files used in your application.

Build

Finally, run install and buidl to generate the JS and types for publishing your module to npm.

yarn install
yarn buidl

Advanced Usage

See our advanced usage documentation.

Disclaimer

AS DESCRIBED IN THE OSMOSIS LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.

No developer or entity involved in creating Telescope will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the Telescope code or Telescope CLI, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.

Comments
  • Incorrect casing on cosmos LCD query response types

    Incorrect casing on cosmos LCD query response types

    I'm pretty ignorant of the mechanics of proto generation, and am not positive this is a telescope issue. I'm also working with the upcoming .46 cosmos release, which might be relevant

    Basically, I have a repo (https://github.com/haveanicedavid/groups-ui) which is using a package (https://github.com/haveanicedavid/cosmos-groups-ts) generated through telescope, where I

    1. pulled down the latest tagged SDK .46 release (v0.46.1)
    2. copied the proto tags over from /proto in SDK to /proto in the telescope proj
    3. pulled in missing proto files from the buf registry (buf export buf.build/cosmos/cosmos-sdk:$(curl -sS https://api.github.com/repos/cosmos/cosmos-sdk/commits/v0.46.1 | jq -r .sha) --output ./proto in the telescope proj)
    4. ran the codegen script yarn codegen (fixing proto errors til it runs correctly) and published to NPM

    With that, i've been able to generate an LCD client through the factory and successfully run queries, and the shape of response data on those queries is correct, but the casing is off because LCD / REST sends properties in snake_case. For example the GroupInfo interface: image

    compared to the response (totalWeight vs total_weight, created_at vs createdAt): image

    Again, I’m not sure this is an issue with telescope or on my end (there are a lot of moving parts), but it seems like the response data for LCD / REST is structured as snake_case: https://docs.cosmos.network/master/modules/group/#rest so presumably this could impact all LCD query clients generated with cosmos protos

    opened by haveanicedavid 22
  • missing fields

    missing fields

    cosmos/crypto/keyring/v1/record

      // Ledger item
      message Ledger {
        hd.v1.BIP44Params path = 1;
      }
    
    +export interface Record_Ledger {}
     
    -export interface Record_Ledger {
    -  path: BIP44Params;
    -}
    
    opened by pyramation 10
  • duration type for `MsgLockTokens` not compatible with latest `ts-proto` output

    duration type for `MsgLockTokens` not compatible with latest `ts-proto` output

    messages that are successful in the API look like this, where the duration is basically a string:

    {
          "type": "osmosis/lockup/lock-tokens",
          "value": {
            "owner": "osmo1g5555555555555555555555",
            "duration": "1209600000000000",
            "coins": [
              {
                "amount": "367423715380310220",
                "denom": "gamm/pool/1"
              }
            ]
          }
        }
    

    However, the go repository refers to a google duration, which in turn looks like

    {
       seconds: '1209600', // technically of type "Long"
       nanos: 0
    }
    

    the problem

    The ts-proto output for MsgLockTokens.fromPartial() results in this nested property { seconds, nanos}, not the string that the API expects.

    ⚙️ task 
    opened by pyramation 10
  • DeepPartial vs Partial

    DeepPartial vs Partial

    from telegram:

    ...can't compile my proto because Long.fromValue() in ts, it can't casting loing type in DeepPartial... Can you help me? Below is sample code.

    fromPartial(object: DeepPartial<TxResponse>): TxResponse {
        // ...
        message.height = object.height !== undefined && object.height !== null ? Long.fromValue(object.height) : Long.ZERO;
        // ....
    }
    

    Error is occured in Long.fromValue(object.height) bacause it can cast only Long type but object.height is not a Long type in my environment. It is declared Long type, but in DeepPartial maybe it is not just Long type...

    But it is correctly compiled with changing DeepPartial to Partial.

    opened by pyramation 9
  • Issue With Google protos

    Issue With Google protos

    Bare with me as this is probably user error. I'm newish to ts projects and dependencies, so it's probably something simple. This is what I'm getting with my tsc build of a project I'm working on. I've spent quite a bit of time trying different things, including building the osmojs module in node_modules from scratch, which failed with a babel error on an 'unexpected unum'.

    High level, I'm just trying to write a cli to do some swaps. I'm familiar enough with js to I think pull it off in ts, but don't know Go well enough to use the normal osmosis-sdk. If I'm headed down the wrong path I'm open to suggestions!

    tsc output

    node_modules/osmojs/types/proto/google/bundle.d.ts:664:53 - error TS2339: Property 'LoggingServiceV2ClientImpl' does not exist on type 'typeof import("<project-home>/node_modules/osmojs/types/proto/google/logging/v2/logging")'.
    
    664             LoggingServiceV2ClientImpl: typeof _675.LoggingServiceV2ClientImpl;
                                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    node_modules/osmojs/types/proto/google/bundle.d.ts:724:53 - error TS2339: Property 'MetricsServiceV2ClientImpl' does not exist on type 'typeof import("<project-home>/node_modules/osmojs/types/proto/google/logging/v2/logging_metrics")'.
    
    724             MetricsServiceV2ClientImpl: typeof _674.MetricsServiceV2ClientImpl;
                                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    node_modules/osmojs/types/proto/google/bundle.d.ts:1007:52 - error TS2339: Property 'ConfigServiceV2ClientImpl' does not exist on type 'typeof import('<project home>node_modules/osmojs/types/proto/google/logging/v2/logging_config")'.
    
    1007             ConfigServiceV2ClientImpl: typeof _673.ConfigServiceV2ClientImpl;
                                                            ~~~~~~~~~~~~~~~~~~~~~~~~~
    
    node_modules/osmojs/types/proto/google/bundle.d.ts:1102:43 - error TS2339: Property 'OperationsClientImpl' does not exist on type 'typeof import("<project home>/node_modules/osmojs/types/proto/google/longrunning/operations")'.
    
    1102         OperationsClientImpl: typeof _676.OperationsClientImpl;
    

    Applicable Code

    import {
        AminoTypes,
        SigningStargateClient
    } from '@cosmjs/stargate';
    import { Registry } from '@cosmjs/proto-signing';
    import { defaultRegistryTypes } from '@cosmjs/stargate';
    import { OfflineSigner } from '@cosmjs/proto-signing'
    import { osmosis } from 'osmojs';
    

    tsconfig.json

    {
      "compilerOptions": {
        "target": "es6",
        "allowJs": true,
        "noImplicitAny": false,
        "module": "commonjs",
        "sourceMap": true,
        "outDir": "out",
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "moduleResolution": "node"
      },
      "include": ["src/*.ts"],
      "exclude": ["**/node_modules", "**/.*/"],
    }
    

    package.json dependencies (some probably unecessary, but whatevs at this point)

      "dependencies": {
        "@cosmjs/launchpad": "^0.27.1",
        "@cosmjs/proto-signing": "^0.28.4",
        "@cosmjs/stargate": "^0.28.4",
        "@keplr-wallet/types": "latest",
        "axios": "latest",
        "osmojs": "^0.4.45",
        "secretjs": "latest",
        "ts-node": "^10.8.0",
        "@protobufs/osmosis": "latest"
      }
    
    opened by mpthomas 9
  • `encode()`/`decode()` methods

    `encode()`/`decode()` methods

    • [x] Long[]

    https://github.com/pyramation/protobuf-example-reference/blob/master/ts/cosmwasm/wasm/v1/query.ts#L184 https://github.com/pyramation/protobuf-example-reference/blob/master/ts/cosmwasm/wasm/v1/query.ts#L1407-L1411

    • [x] CustomType

    https://github.com/pyramation/protobuf-example-reference/blob/master/ts/cosmos/tx/v1beta1/tx.ts#L1430-L1446

    • [x] Enums

    https://github.com/pyramation/protobuf-example-reference/blob/master/ts/cosmos/tx/v1beta1/tx.ts#L1430-L1446

    opened by pyramation 9
  • namespace and package not supported

    namespace and package not supported

    First off, thank you for this impressive package!

    Im busy running the transpile step on our chains protobuf files and I am getting this error above.

    How would I address this ? It appears on the surface to be a support issue for the protocol buffers but I may be wrong.

    Can someone add some insight here?

    opened by demondayza 7
  • extracting amino type names from sdk systematically

    extracting amino type names from sdk systematically

    Error: Multiple types are registered with Amino type identifier 'cosmos-sdk/MsgVote': '/cosmos.gov.v1beta1.MsgVote', '/cosmos.group.v1.MsgVote'. Thus fromAmino cannot be performed.
    
    opened by pyramation 5
  • from partial implementation for #85

    from partial implementation for #85

    This is a potential solution for calling toUtf8/JSON.stringify for the msg prop in MsgExecuteContract.

    This is a generalized system, however, as we can parse the proto options [ (gogoproto.casttype) = "RawContractMessage" ]

    https://github.com/CosmWasm/wasmd/blob/main/proto/cosmwasm/wasm/v1/tx.proto#L58

    opened by pyramation 5
  • LCD client

    LCD client

    We can parse queries and get URLs and generate LCD client with types.

    • [ ] plugin to hide/show certain modules/routes
    • [ ] combine into nice API similar to secret.js does with modules:
    queryClient.osmosis.numPools();
    queryClient.osmosis.pool('...');
    
    opened by pyramation 5
  • new amino registry not correct for osmosis gamm v1beta

    new amino registry not correct for osmosis gamm v1beta

    to/from amino with latest code doesn't serialize correctly — I'm testing out the latest with the prototype and getting serialization errors:

    Error: Broadcasting transaction failed with code 4 (codespace: sdk). Log: signature verification failed; please verify account number (441730), sequence (133) and chain-id (osmosis-1): unauthorized
        at SigningStargateClient.broadcastTx
    
    • [ ] determine how to properly manage the Long type when serializing
    opened by pyramation 5
  • helpers for nested create Any objects

    helpers for nested create Any objects

    https://github.com/cosmos/groups-ui/blob/master/src/shared-state/groups-store.ts#L363

    • [ ] fix type issue in comment below
    • [ ] fix the interface so developer doesn't have to encode decisionPolicy field
    import Long from 'long';
    const {
        createGroupWithPolicy
    } = cosmos.group.v1.MessageComposer.withTypeUrl;
    
    const {
        PercentageDecisionPolicy   
    } = cosmos.group.v1;
    
    const msg = createGroupWithPolicy({
        admin: 'a string',
        groupMetadata: 'string here',
        groupPolicyAsAdmin: true,
        groupPolicyMetadata: 'a string here too',
        members: [], // MemberRequest[],
        decisionPolicy: { // types here aren't exactly happy with the encode function for some reason...
            // WE CAN IMPROVE THIS....
            typeUrl: '/cosmos.group.v1.PercentageDecisionPolicy',
            value: PercentageDecisionPolicy.encode({
                percentage: 'a string',
                windows: {
                    votingPeriod: {
                        nanos: 0,
                        seconds: Long.fromValue(100)
                    },
                    minExecutionPeriod: {
                        nanos: 0,
                        seconds: Long.fromValue(100)
                    }
                }
            }).finish()
        }
    })
    
    opened by pyramation 1
  • [sprint] encoding cleanup

    [sprint] encoding cleanup

    • [ ] #238
    • [ ] #239
    • [ ] #247
    • [ ] #211
    • [ ] #142
    • [ ] https://github.com/osmosis-labs/osmojs/issues/12
    • [ ] https://github.com/osmosis-labs/osmojs/issues/5
    • [ ] #277
    • [ ] #141
    • [ ] #140
    • [ ] #118
    • [ ] #279
    • [ ] determine if we should support durations as strings
    • [ ] timestamps
    epic 
    opened by pyramation 0
  • toAmino/fromAmino for `ibc.core.client.v1.Height`

    toAmino/fromAmino for `ibc.core.client.v1.Height`

    currently we break in the code on Height by introspecting the props

                case 'Height': {
                    // type: 'ibc.core.client.v1.Height'
                    if
                        ((proto.fields.revisionNumber && proto.fields.revisionHeight) ||
                        (proto.fields.revision_number && proto.fields.revision_height)) {
                        [].push.apply(body, fromAminoMessages.height(context, name, proto));
                    }
                    break;
                }
    
    • [ ] can we add a parsedType to messages, not just fields? So we can get ibc.core.client.v1.Height? (instead of looking at field names)
    • [ ] clean up casing
    • [ ] look at original toAmino/fromAmino (below) — do we need the omitDefault?
    export const AminoConverter = {
      "/ibc.applications.transfer.v1.MsgTransfer": {
        aminoType: "cosmos-sdk/MsgTransfer",
        toAmino: ({
          sourcePort,
          sourceChannel,
          token,
          sender,
          receiver,
          timeoutHeight,
          timeoutTimestamp
        }: MsgTransfer): AminoMsgTransfer["value"] => {
          return {
            source_port: sourcePort,
            source_channel: sourceChannel,
            token: {
              denom: token.denom,
              amount: Long.fromValue(token.amount).toString()
            },
            sender,
            receiver,
            timeout_height: timeoutHeight ? {
              revision_height: omitDefault(timeoutHeight.revisionHeight)?.toString(),
              revision_number: omitDefault(timeoutHeight.revisionNumber)?.toString()
            } : {},
            timeout_timestamp: timeoutTimestamp.toString()
          };
        },
        fromAmino: ({
          source_port,
          source_channel,
          token,
          sender,
          receiver,
          timeout_height,
          timeout_timestamp
        }: AminoMsgTransfer["value"]): MsgTransfer => {
          return {
            sourcePort: source_port,
            sourceChannel: source_channel,
            token: {
              denom: token.denom,
              amount: token.amount
            },
            sender,
            receiver,
            timeoutHeight: timeout_height ? {
              revisionHeight: Long.fromString(timeout_height.revision_height || "0", true),
              revisionNumber: Long.fromString(timeout_height.revision_number || "0", true)
            } : undefined,
            timeoutTimestamp: Long.fromString(timeout_timestamp)
          };
        }
      }
    };
    
    opened by pyramation 0
  • add option to generate a providers

    add option to generate a providers

    https://twitter.com/_srph/status/1603357271328972802?s=20&t=kU9I9uRyeJKGtmnDWOOLHw

    Absolutely 🔥. One suggestion: how about a step further and include an RpcProvider out of the box - call createRpcQueryHooks once and share it globally?

    cc @srph

    opened by pyramation 1
Owner
null
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
An experimental transpiler to bring tailwind macros to SWC 🚀

stailwc (speedy tailwind compiler) This is an experimental SWC transpiler to bring compile time tailwind macros to SWC (and nextjs) a-la twin macro. T

Alexander Lyon 140 Jan 3, 2023
JavaScript Express.js app serving static vanilla JS. This sample app is used in Microsoft Docs to demonstrate how to integrate Azure Storage, Azure Cosmos DB, and Azure Active Directory.

JavaScript on Azure Learn Path - Module 2 - Deploying a basic app to Azure This Learn module requires the following Azure resources to deploy correctl

Azure Samples 13 Dec 31, 2022
🪐 Ultralight Cosmos utilities for JS and TS

Essential Cosmos Ultralight Cosmos utilities for JS and TS ?? The TINIEST code size possible ʦ Fully typed with TypeScript (also works with JavaScript

Earnifi 7 Oct 24, 2022
Auto-compounder app for Cosmos blockchains using Authz

REStake REStake allows delegators to grant permission for a validator to compound their rewards, and provides a script validators can run to find thei

ECO Stake 237 Dec 29, 2022
Cosmos chain registry ⚛️

chain-registry The npm package for the Official Cosmos chain registry npm install chain-registry example import { assets, chains, ibc } from 'chain-r

Cosmology 19 Dec 8, 2022
A wallet connector for the Cosmos ⚛️

cosmos-kit A wallet adapter for react with mobile WalletConnect support for the Cosmos ecosystem. Getting Started @cosmos-kit/react A wallet adapter f

Cosmology 81 Dec 20, 2022
:books: The definitive guide to TypeScript and possibly the best TypeScript book :book:. Free and Open Source 🌹

TypeScript Deep Dive I've been looking at the issues that turn up commonly when people start using TypeScript. This is based on the lessons from Stack

Basarat Ali Syed 18.7k Jan 4, 2023
Variant types in Roblox TypeScript - Ported from Vanilla TypeScript

Variant (for Roblox) This is a roblox typescript variant (heh, pun) of Variant. See the Variant documentation on how to use Variant. A variant type is

Australis 2 Jun 3, 2022
A Lua plugin, written in TypeScript, to write TypeScript (Lua optional).

typescript.nvim A minimal typescript-language-server integration plugin to set up the language server via nvim-lspconfig and add commands for convenie

Jose Alvarez 315 Dec 29, 2022
typescript-to-jsonschema generates JSON Schema files from your Typescript sources.

fast-typescript-to-jsonschema English | 简体中文 a tool generate json schema from typescript. Feature compile Typescript to get all type information conve

yunfly 21 Nov 28, 2022
Convert some JavaScript/TypeScript code string into a .d.ts TypeScript Declaration code string

convert-to-dts Converts the source code for any .js or .ts file into the equivalent .d.ts code TypeScript would generate. Usage import { convertToDecl

Lily Scott 11 Mar 3, 2022
Screeps Typescript Starter is a starting point for a Screeps AI written in Typescript.

Screeps Typescript Starter Screeps Typescript Starter is a starting point for a Screeps AI written in Typescript. It provides everything you need to s

null 3 Jan 27, 2022
Movehat is a TypeScript SDK for Move on Sui built on top of Sui's TypeScript SDK and our fork of Ian Macalinao's `move-ts`.

Movehat Movehat is a TypeScript SDK for Move on Sui built on top of Sui's TypeScript SDK and our fork of Ian Macalinao's move-ts. Movehat aspires to b

Pentagon 10 Sep 30, 2022
🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

?? HypeScript Introduction This is a simplified implementation of TypeScript's type system that's written in TypeScript's type annotations. This means

Ronen Amiel 1.8k Dec 20, 2022
A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

CTSP- Create TS Project A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and conf

Jean Rodríguez 7 Sep 13, 2022
This project is a boilerplate for Next and TypeScript projects. This template was built with Vite, TypeScript and Stitches.

Awesome Template Stitches — NextJS, TypeScript, Stitches and Design Tokens Summary About this template Avaliale scripts Other scripts available Main t

Diego Silva 14 Dec 29, 2022