Skip to content

Commit

Permalink
main
Browse files Browse the repository at this point in the history
  • Loading branch information
pyramation committed Apr 18, 2024
1 parent 58db22e commit e0cbf2d
Show file tree
Hide file tree
Showing 5 changed files with 522 additions and 22 deletions.
8 changes: 4 additions & 4 deletions boilerplates/lerna-workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
],
"scripts": {
"clean": "lerna run clean",
"build": "lerna run build",
"symlink": "symlink-workspace",
"build": "lerna run build --stream",
"symlink": "symlink-workspace --logLevel error",
"postinstall": "yarn symlink"
},
"devDependencies": {
Expand All @@ -35,9 +35,9 @@
"lerna": "^6",
"prettier": "^3.0.2",
"strip-ansi": "^6",
"symlink-workspace": "^1.0.0",
"symlink-workspace": "^1.1.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"typescript": "^5.1.6"
}
}
}
15 changes: 10 additions & 5 deletions boilerplates/telescope-module/.questions.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
"message": "Enter author email",
"required": true
},
{
"name": "__CHAINNAME__",
"message": "Enter chain name in all lowercase, e.g. osmosis",
"required": true
},
{
"name": "__CHAIN_UPPER__",
"message": "Enter chain name in super case, e.g. Osmosis",
"required": true
},
{
"name": "__MODULENAME__",
"message": "Enter the module name",
Expand All @@ -19,11 +29,6 @@
"message": "Enter the module description",
"required": true
},
{
"name": "__REPONAME__",
"message": "Enter the repository name",
"required": true
},
{
"name": "__USERNAME__",
"message": "Enter your github username",
Expand Down
255 changes: 251 additions & 4 deletions boilerplates/telescope-module/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,279 @@
# __MODULENAME__
# __PACKAGE_IDENTIFIER__

<p align="center">
<img src="https://user-images.githubusercontent.com/545047/188804067-28e67e5e-0214-4449-ab04-2e0c564a6885.svg" width="80"><br />
__MODULEDESC__
</p>


## install

```sh
npm install __MODULENAME__
npm install __PACKAGE_IDENTIFIER__
```
## Table of contents

- [__MODULENAME__](#__MODULENAME__)
- [__PACKAGE_IDENTIFIER__](#__PACKAGE_IDENTIFIER__)
- [Install](#install)
- [Table of contents](#table-of-contents)
- [Usage](#usage)
- [RPC Clients](#rpc-clients)
- [Composing Messages](#composing-messages)
- Cosmos, CosmWasm, and IBC
- [CosmWasm](#cosmwasm-messages)
- [IBC](#ibc-messages)
- [Cosmos](#cosmos-messages)
- [Wallets and Signers](#connecting-with-wallets-and-signing-messages)
- [Stargate Client](#initializing-the-stargate-client)
- [Creating Signers](#creating-signers)
- [Broadcasting Messages](#broadcasting-messages)
- [Advanced Usage](#advanced-usage)
- [Developing](#developing)
- [Credits](#credits)

## Developing
## Usage
### RPC Clients

```js
import { __CHAINNAME__ } from '__PACKAGE_IDENTIFIER__';

const { createRPCQueryClient } = __CHAINNAME__.ClientFactory;
const client = await createRPCQueryClient({ rpcEndpoint: RPC_ENDPOINT });

// now you can query the cosmos modules
const balance = await client.cosmos.bank.v1beta1
.allBalances({ address: '__CHAINNAME__1addresshere' });

// you can also query the __CHAINNAME__ modules
const balances = await client.__CHAINNAME__.exchange.v1beta1
.exchangeBalances()
```

### Composing Messages

Import the `__CHAINNAME__` object from `__PACKAGE_IDENTIFIER__`.

```js
import { __CHAINNAME__ } from '__PACKAGE_IDENTIFIER__';

const {
createSpotLimitOrder,
createSpotMarketOrder,
deposit
} = __CHAINNAME__.exchange.v1beta1.MessageComposer.withTypeUrl;
```

#### CosmWasm Messages

```js
import { cosmwasm } from "__PACKAGE_IDENTIFIER__";

const {
clearAdmin,
executeContract,
instantiateContract,
migrateContract,
storeCode,
updateAdmin
} = cosmwasm.wasm.v1.MessageComposer.withTypeUrl;
```

#### IBC Messages

```js
import { ibc } from '__PACKAGE_IDENTIFIER__';

const {
transfer
} = ibc.applications.transfer.v1.MessageComposer.withTypeUrl
```

#### Cosmos Messages

```js
import { cosmos } from '__PACKAGE_IDENTIFIER__';

const {
fundCommunityPool,
setWithdrawAddress,
withdrawDelegatorReward,
withdrawValidatorCommission
} = cosmos.distribution.v1beta1.MessageComposer.fromPartial;

const {
multiSend,
send
} = cosmos.bank.v1beta1.MessageComposer.fromPartial;

const {
beginRedelegate,
createValidator,
delegate,
editValidator,
undelegate
} = cosmos.staking.v1beta1.MessageComposer.fromPartial;

const {
deposit,
submitProposal,
vote,
voteWeighted
} = cosmos.gov.v1beta1.MessageComposer.fromPartial;
```

## Connecting with Wallets and Signing Messages

⚡️ For web interfaces, we recommend using [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit). Continue below to see how to manually construct signers and clients.

Here are the docs on [creating signers](https://docs.cosmology.zone/cosmos-kit) in cosmos-kit that can be used with Keplr and other wallets.

### Initializing the Stargate Client

Use `getSigning__CHAIN_UPPER__Client` to get your `SigningStargateClient`, with the proto/amino messages full-loaded. No need to manually add amino types, just require and initialize the client:

```js
import { getSigning__CHAIN_UPPER__Client } from '__MODULENAME__';

const stargateClient = await getSigning__CHAIN_UPPER__Client({
rpcEndpoint,
signer // OfflineSigner
});
```
### Creating Signers

To broadcast messages, you can create signers with a variety of options:

* [cosmos-kit](https://docs.cosmology.zone/cosmos-kit) (recommended)
* [keplr](https://docs.keplr.app/api/cosmjs.html)
* [cosmjs](https://gist.github.com/webmaster128/8444d42a7eceeda2544c8a59fbd7e1d9)
### Amino Signer

Likely you'll want to use the Amino, so unless you need proto, you should use this one:

```js
import { getOfflineSignerAmino as getOfflineSigner } from 'cosmjs-utils';
```
### Proto Signer

```js
import { getOfflineSignerProto as getOfflineSigner } from 'cosmjs-utils';
```

WARNING: NOT RECOMMENDED TO USE PLAIN-TEXT MNEMONICS. Please take care of your security and use best practices such as AES encryption and/or methods from 12factor applications.

```js
import { chains } from 'chain-registry';

const mnemonic =
'unfold client turtle either pilot stock floor glow toward bullet car science';
const chain = chains.find(({ chain_name }) => chain_name === '__CHAINNAME__');
const signer = await getOfflineSigner({
mnemonic,
chain
});
```
### Broadcasting Messages

Now that you have your `stargateClient`, you can broadcast messages:

```js
const { send } = cosmos.bank.v1beta1.MessageComposer.withTypeUrl;

const msg = send({
amount: [
{
denom: 'coin',
amount: '1000'
}
],
toAddress: address,
fromAddress: address
});

const fee: StdFee = {
amount: [
{
denom: 'coin',
amount: '864'
}
],
gas: '86364'
};
const response = await stargateClient.signAndBroadcast(address, [msg], fee);
```

## Advanced Usage


If you want to manually construct a stargate client

```js
import { OfflineSigner, GeneratedType, Registry } from "@cosmjs/proto-signing";
import { AminoTypes, SigningStargateClient } from "@cosmjs/stargate";

import {
cosmosAminoConverters,
cosmosProtoRegistry,
cosmwasmAminoConverters,
cosmwasmProtoRegistry,
ibcProtoRegistry,
ibcAminoConverters,
__CHAINNAME__AminoConverters,
__CHAINNAME__ProtoRegistry
} from '__MODULENAME__';

const signer: OfflineSigner = /* create your signer (see above) */
const rpcEndpint = 'https://rpc.cosmos.directory/__CHAINNAME__'; // or another URL

const protoRegistry: ReadonlyArray<[string, GeneratedType]> = [
...cosmosProtoRegistry,
...cosmwasmProtoRegistry,
...ibcProtoRegistry,
...__CHAINNAME__ProtoRegistry
];

const aminoConverters = {
...cosmosAminoConverters,
...cosmwasmAminoConverters,
...ibcAminoConverters,
...__CHAINNAME__AminoConverters
};

const registry = new Registry(protoRegistry);
const aminoTypes = new AminoTypes(aminoConverters);

const stargateClient = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer, {
registry,
aminoTypes
});
```

## Developing

When first cloning the repo:

```
yarn
yarn build
```

### Codegen

Contract schemas live in `./contracts`, and protos in `./proto`. Look inside of `scripts/codegen.js` and configure the settings for bundling your SDK and contracts into `__PACKAGE_IDENTIFIER__`:

```
yarn codegen
```

### Publishing

Build the types and then publish:

```
yarn build
yarn publish
```

## Related

Checkout these related projects:
Expand Down
13 changes: 7 additions & 6 deletions boilerplates/telescope-module/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "__MODULENAME__",
"name": "__REPONAME__",
"version": "0.0.1",
"author": "__USERFULLNAME__ <__USEREMAIL__>",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/__USERNAME__/__MODULENAME__"
"url": "https://github.com/__USERNAME__/__REPONAME__"
},
"license": "SEE LICENSE IN LICENSE",
"publishConfig": {
Expand All @@ -16,8 +16,9 @@
],
"scripts": {
"clean": "lerna run clean",
"build": "lerna run build",
"symlink": "symlink-workspace",
"build": "lerna run build --stream",
"codegen": "lerna run codegen --stream --scope ",
"symlink": "symlink-workspace --logLevel error",
"postinstall": "yarn symlink"
},
"devDependencies": {
Expand All @@ -35,9 +36,9 @@
"lerna": "^6",
"prettier": "^3.0.2",
"strip-ansi": "^6",
"symlink-workspace": "^1.0.0",
"symlink-workspace": "^1.1.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"typescript": "^5.1.6"
}
}
}
Loading

0 comments on commit e0cbf2d

Please sign in to comment.