GithubHelp home page GithubHelp logo

cosmology's Introduction

THIS LIBRARY IS DEPRECATED

cosmology

npm install -g cosmology

Use cosmology to build web3 applications on top of Osmosis and the Cosmos. Make cryptocurrency trades, join liquidity pools, and stake rewards.

usage

CLI and user prompts

Not sure what to do? Simply type cosmology. It will prompt you with options.

$ cosmology 
? [cmd] what do you want to do? 
  keychain-del 
  keychain-get 
  keychain-set 
❯ list-apis 
  list-pools 
  list-prices 
  load-recipe 

Then once you learn the api, you can start supplying the parameters.

cosmology <commandname>

commands

rebalance

The rebalance command will make a series of swaps on your behalf. It will prompt you to choose the coins you are willing to sell to create a new balance based on the pools you want to enter.

cosmology rebalance 

Example with parameters

cosmology rebalance \
    --chainId osmosis-1 \
    --restEndpoint https://lcd-osmosis.blockapsis.com \
    --rpcEndpoint https://osmosis.validator.network \
    --slippage 1 

join

The join command will join a pool.

cosmology join 

Example with parameters

cosmology join \
    --keychain my-mnemonic-name \
    --chainId osmosis-1 \
    --restEndpoint https://lcd-osmosis.blockapsis.com \
    --poolId 601
    --max

lock

The lock command will lock your gamms tokens for staking so you can earn rewards.

cosmology lock 

Example with parameters

cosmology lock \
    --keychain my-mnemonic-name \
    --chainId osmosis-1 \
    --restEndpoint https://lcd-osmosis.blockapsis.com \
    --poolId 601 \
    --duration 14

claim

Claim rewards from staking.

cosmology claim

Example with parameters

cosmology claim \
  --keychain my-mnemonic-name \
  --chainToken CMDX \
  --minAmount 1 \
  --restEndpoint https://rest.comdex.one \
  --rpcEndpoint https://rpc.comdex.one

delegate

Stake tokens to a validator.

cosmology delegate

Example with parameters

cosmology delegate \
  --keychain my-mnemonic-name \
  --chainToken CMDX \
  --minAmount 1 \
  --restEndpoint https://rest.comdex.one \
  --rpcEndpoint https://rpc.comdex.one \
  --validatorAddress comdexvaloper1mzxzxkzajancc63gtwt9x9zw2qfv9k9ar7ka34

env vars

While everything can be done with parameters, you can also just supply env vars and cosmology won't prompt you for those values:

env var optional description
MNEMONIC Yes cosmos mnemonic, either plain-text or encrypted
ENCRYPTED_SALT Yes used for encrypting/decrypting mnemonics
KEYCHAIN_ACCOUNT Yes used for storing info in OSX keychain account
CHAIN_ID Yes used for getting chain info, e.g. osmosis-1
REST_ENDPOINT Yes used for setting LCD endpoint
RPC_ENDPOINT Yes used for setting RCP endpoint

mnemonics

There are a few methods to deal with mnemonics.

  1. plain text env var MNEMONIC
  2. encrypted key with a salt
  3. mac OSX keychain

METHOD 1 - plain text

(Not recommended) video here

export MNEMONIC="action brisk disagree just bunker design wasp hand night ghost runway fluid"
# now you can run cosmology

cosmology rebalance

METHOD 2 - encrypted salt via env var ENCRYPTED_SALT

video here

The encrypted salt is the recommended usage so that you don't store plain-text mnemonics.

1 First, generate a salt.

cosmology salt-generate --saltBytes 64
> GRHeG5r9nojio7PmCuNnLEh0Hglwvw1Bn87ipIMeyhPFVJk9i5eWtno7m7pa8FPRjbsd2LqCjEsR8/Hiyp9lLg==

2 Now encrypt this salt value

(Yes, we are encrypting a salt with a salt, or password)

cosmology salt-encrypt \
     --secret GRHeG5r9nojio7PmCuNnLEh0Hglwvw1Bn87ipIMeyhPFVJk9i5eWtno7m7pa8FPRjbsd2LqCjEsR8/Hiyp9lLg==

Now, store that value securely, and remember your password. Test the salt-encrypt and salt-decrypt commands a few times so you understand how it works.

3 Now you can use it in env var ENCRYPTED_SALT

export ENCRYPTED_SALT=U2FsdGVkX183aSMtLlWua/uig/Qqd99TBILc63iW1AsJaKGykZGPvA/DXByjYtws7drSVlipMPsMLrePajBtRyFP7tZOLrlUuL+xlhcsRAm0DcTRV+VDsnDQVykSDhSyl1RYf03SsLgUsYMvsixWFA==

# now the user will be prompted for "salt" which is the password used to decrypt the encryption key
# the mnemonic will be automatically decrypted by the system
cosmology

METHOD 3 - keychain

video here

We can leverage the Mac OSX keychain. Don't worry though, we ONLY use encryption via the encrypted salt, even if some of you happen to trust storing mnemonics in OSX keychain. We only store encrypted values, period.

1 create an encryption key and encrypt it as described in the previous step

create an ENCRYPTED_SALT and store it securely.

2 add your mnemonic to your keychain

  • name is how you'll reference
  • password is your actual mnemonic
  • salt is the salt for your encrypted salt key
$ cosmology keychain-set
? [name] name my-special-mnemonic-name-1
? [password] password [hidden]
? [salt] enter the salt [hidden]

Test it!

$ cosmology keychain-get \
 --name my-special-mnemonic-name-1

testing

first start the tests

cd ./packages/cosmology
yarn test:watch

hit "p" and then type a search string to scope to the name your test

developing the CLI

if you need to edit the CLI

cd ./packages/cosmology
export MNEMONIC="mammal wrestle hybrid cart choose flee transfer filter fly object swamp rookie"
export CHAIN_ID=osmosis-testnet-0
export RPC_ENDPOINT=http://143.244.147.126:26657

yarn run dev

Useful Links for Developers of Cosmology

RPC Docs

https://v1.cosmos.network/rpc/v0.41.4

LCD Docs

https://osmosis.stakesystems.io/static/openapi/

Validator Docs

https://api-osmosis.imperator.co/swagger

Other

https://github.com/osmosis-labs/awesome#publicly-available-endpoints

https://www.notion.so/Stake-Systems-LCD-RPC-gRPC-Instances-04a99a9a9aa14247a42944931eec7024

known issues

  • defaults to NOT using pools with less than 100k in liquidity
  • smaller tokens with volatility may need higher slippage values

Credits

🛠 Built by Cosmology — if you like our tools, please consider delegating to our validator ⚛️

Code built with the help of these related projects:

  • @cosmology/telescope a "babel for the Cosmos", Telescope is a TypeScript Transpiler for Cosmos Protobufs.
  • osmojs OsmosJS makes it easy to compose and broadcast Osmosis and Cosmos messages.

Disclaimer

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

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

cosmology's People

Contributors

aidanaden avatar alexanderclarktx avatar dependabot[bot] avatar njerschow avatar pyramation avatar solumos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cosmology's Issues

CoinGecko API response error: AxiosError: connect ETIMEDOUT 162.125.6.1:443

const rpcEndpoint = "https://rpc.cosmos.directory/osmosis"
const client = await osmosis.ClientFactory.createRPCQueryClient({ rpcEndpoint });

const {
pools,
prices,
pairs,
prettyPools
} = await getPoolsPricesPairs(client);

CoinGecko API response error: AxiosError: connect ETIMEDOUT 162.125.6.1:443
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
port: 443,
address: '162.125.6.1',
syscall: 'connect',
code: 'ETIMEDOUT',
errno: -4039,

Is there something wrong with my network ?

TypeError: routes.map is not a function

const routes = {
"poolId": "1",
"tokenOutDenom": "uosmo"
}

const msg = swapExactAmountIn({
sender: '',
routes,
tokenIn: coin(1000, 'uosmo'),
tokenOutMinAmount: 10000
});

I using something right this and get an error routes.map,when I try to use lookupRoutesForTrade,but I dont know what exactly the beliefValue and pair?

Old assetlist.json with missing tokens

The current assetlist.json has not been updated for 2 months or so, hence there are various new tokens added by osmosis that is missing. The existing assetlist.json url is also invalid and returns a 404.

Method getPools returns wrong LcdPool[] properties

Hi,
I got LcdPool[] by doing :

  • Make a client by instancing OsmosisApiClient
  • Call getPools(). Get a PoolsResponse containing LcdPool[]

The issue is that the received LcdPool[] have properties like pool_assets and not poolAssets. Same for total_weight and pool_params.
So, I have to "clean" my LcdPool[] before using it. With, for example if (pool.pool_params) pool.poolParams = pool.pool_params

Here is LcdPool : https://github.com/cosmology-tech/cosmology/blob/main/packages/core/src/types.ts#L284
Here is PoolsResponse : https://github.com/cosmology-tech/cosmology/blob/main/packages/core/src/clients/osmosis.ts#L21
Here is the method getPools() of OsmosisApiClient : https://github.com/cosmology-tech/cosmology/blob/main/packages/core/src/clients/osmosis.ts#L33

Wdyt ?
Thank you for your repo and your time.

Update pools query pagination limit to 2000

The current pagination limit when querying for osmosis pools is 1000, with the total number of pools currently at 925 (verify here).

To deal with the growing number of pools, pagination limit should be increased to 1500 to ensure all pools are queried.

PS. would be very helpful if anyone knows of a way to query the pools endpoint such that all pools are returned WITHOUT having to set the pagination.limit query parameter (so we don't have to update this again)

swap error while the same swap work in web app

use this cmd to swap

cosmology swap \
    --chainId osmosis-1 \
    --restEndpoint https://lcd-osmosis.blockapsis.com/ \
    --rpcEndpoint https://osmosis.validator.network/ \
    --sell UST \
    --buy ATOM \
    --value 0.1 \
    --slippage 1  

TX failed:
failed to execute message; message index: 0: ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2 token is lesser than min amount: calculated amount is lesser than min amount
TX: https://www.mintscan.io/osmosis/txs/F08A98B4F7932CDB3722FADF924B321A8FE0F34589485E40ADB513D7F70378A2

while the same swap succ at app, also using this cmd to swap atom/osmo succ, but swap ust would occur this error

getPoolsPricesPairs error - unknown pool type

Whe I run the getPoolsPricesPairs function :

this.client = await osmosis.ClientFactory.createRPCQueryClient({ rpcEndpoint: 'https://rpc.osmosis.zone'});
const {
    pools,
    prices,
    pairs
} = await getPoolsPricesPairs(this.client);

I receive this error :
Uncaught Error Error: unknown pool type
at (/home/herraiz/dev/cosmos-osmosis-fetcher/node_modules/@cosmology/core/main/utils/osmo/pools.js:87:25)
at _callee$ (/home/herraiz/dev/cosmos-osmosis-fetcher/node_modules/@cosmology/core/main/utils/osmo/pools.js:76:39)
at tryCatch (/home/herraiz/dev/cosmos-osmosis-fetcher/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:44:17)
at (/home/herraiz/dev/cosmos-osmosis-fetcher/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:125:22)
at (/home/herraiz/dev/cosmos-osmosis-fetcher/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:69:21)
at asyncGeneratorStep (/home/herraiz/dev/cosmos-osmosis-fetcher/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
at _next (/home/herraiz/dev/cosmos-osmosis-fetcher/node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:9)
at processTicksAndRejections (internal/process/task_queues:95:5)

DEPRECATING this repo — use `osmojs`, `@osmonauts/math` and `chain-registry` instead

Hi! Cosmology/core is becoming deprecated soon, as the asset list is "baked in" and the code is legacy.

An ideal workflow is to use osmojs and @osmonauts/math, which we have examples as shown here and in a video/tweet here

then you can use the chain-registry for loading assets, and you can use @chain-registry/osmosis for pre-baked assets, or @chain-registry/utils to build an asset list dynamically:

import { ibc, assets } from 'chain-registry';
import { getAssetLists } from '@chain-registry/utils';

const list = getAssetLists('osmosis', ibc, assets);

Unexpected encoding result

Hello!
I do swapExactAmountIn osmosis message. And usually it's working perfect.
But sometimes, for example in DAI/OSMO pool i encode message with parameter:

tokenIn: {
  "denom": "ibc/0CD3A0285E1341859B5E86B6AB7682F023D03E97607CCC1DC95706411D866DF7",
  "amount": "129433920747610326239"
}

But after in osmosis scan in logs I see this:
https://www.mintscan.io/osmosis/txs/C67C13B32A51CBCD6763CA515DDCABD1523281A849D0C445CFF4A8FC5DEE5E52

"token_in":{
"denom":string"ibc/0CD3A0285E1341859B5E86B6AB7682F023D03E97607CCC1DC95706411D866DF7"
"amount":string"306712231643464927"
}

I cannot understand how the 129433920747610326239 become 306712231643464927.
Please, help!

bug: `makePoolsPretty` is not a function in production build

image

Hi! am currently receiving this error message in production build, but i'm still not sure what the issue is, everything works fine locally.

Node version used is 14.19.2, built with vite 2.8.6

Package.json:

"@cosmjs/proto-signing": "^0.29.0",
"@cosmology/core": "^1.8.0",

Thanks a bunch!

mobx store

This issue is more for design and listing out queries that are needed.

  • all basic like ability to get users balances
  • ability to get users number of tokens inside of a pool

e.g. currently do get number of tokens in a pool

  1. get pools
  2. get prices
  3. convertPoolsToDisplayValues
  4. get the users locked coins
  5. call function getUserPools({pools, lockedPools})

instead, if we used a mobx store, we could wrap this all into a single call and it gets cached and we get simplicity and speed

can't import { messages } from '@cosmology/core';

when i run , it showed :
SyntaxError: Named export 'messages' not found. The requested module '@cosmology/core' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@cosmology/core';
const { messages } = pkg;

upgrade cosmjs

when attempting to upgrading cosmjs libraries to 0.28.1, typeUrl is apparently not recognized

{
  "typeUrl": "/osmosis.gamm.v1beta1.MsgSwapExactAmountIn",
  "value": {
    "sender": "osmo1REDACTED",
    "routes": [
      {
        "poolId": "4",
        "tokenOutDenom": "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2"
      }
    ],
    "tokenIn": {
      "denom": "ibc/1480B8FD20AD5FCAE81EA87584D269547DD4D436843C1D20F15E00EB64743EF4",
      "amount": "3546099"
    },
    "tokenOutMinAmount": "160609"
  }
}
/Users/pyramation/code/cosmology/cosmology/node_modules/@cosmjs/stargate/build/aminotypes.js:21
            throw new Error(`Type URL '${typeUrl}' does not exist in the Amino message type register. ` +
                  ^

Error: Type URL '/osmosis.gamm.v1beta1.MsgSwapExactAmountIn' does not exist in the Amino message type register. If you need support for this message type, you can pass in additional entries to the AminoTypes constructor. If you think this message type should be included by default, please open an issue at https://github.com/cosmos/cosmjs/issues.
    at AminoTypes.toAmino (/Users/pyramation/code/cosmology/cosmology/node_modules/@cosmjs/stargate/src/aminotypes.ts:43:13)
    at /Users/pyramation/code/cosmology/cosmology/node_modules/@cosmjs/stargate/src/signingstargateclient.ts:347:56
    at Array.map (<anonymous>)
    at SigningStargateClient.signAmino (/Users/pyramation/code/cosmology/cosmology/node_modules/@cosmjs/stargate/src/signingstargateclient.ts:347:27)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Issue swapping

Getting an error trying to swap on testnet

TypeError: Cannot read properties of undefined (reading 'amount')
    at _callee$ (/Users/joel/.nvm/versions/node/v16.14.0/lib/node_modules/cosmology/node_modules/@cosmology/cli/main/commands/swap.js:153:83)
cosmology swap \
	--mnemonic "pass panther local rare exit rule robust feel excuse hold arrange fence" \
	--chainId osmo-test-4 \
	--restEndpoint "https://lcd-test.osmosis.zone" \
	--rpcEndpoint "https://rpc-test.osmosis.zone" \
	--sell osmo \
	--buy atom \
	--value 1 \
	--slippage 1

I am using rest/rpc endpoints from here, is this correct?

increase pagination limit for OsmosisApiClient's getPools request

The osmosis frontend currently queries the endpoint https://lcd-osmosis.keplr.app/osmosis/gamm/v1beta1/pools?pagination.limit=1000 with pagination set to 1000 when getting the pool data from the LCD, however the OsmosisApiClient.getPools function continues to query with pagination set to 750, causing a few pools with IDs greater than 750 to be missed out.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.