-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
94 lines (80 loc) · 2.42 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { osmosis } from 'osmojs';
import Long from "long";
import { chains } from 'chain-registry';
import * as dotenv from 'dotenv';
import { getOfflineSignerAmino as getOfflineSigner } from 'cosmjs-utils';
import {
getWalletFromMnemonic, getSigningOsmosisClient, signAndBroadcast, lookupRoutesForTrade, getPoolsPricesPairs, calculateAmountWithSlippage
} from '@cosmology/core';
import { FEES } from 'osmojs';
import { coin } from '@cosmjs/amino';
const {
swapExactAmountIn
} = osmosis.gamm.v1beta1.MessageComposer.withTypeUrl;
const fee = FEES.osmosis.swapExactAmountIn('high'); // low, medium, high
dotenv.config();
const mnemonic = process.env.MNEMONIC;
const signer = await getWalletFromMnemonic({mnemonic, token: 'OSMO'});
const rpcClient = await osmosis.ClientFactory.createRPCQueryClient({ rpcEndpoint: "https://rpc.osmosis.zone" });
const client = await getSigningOsmosisClient({
rpcEndpoint: "https://rpc.osmosis.zone",
signer
});
const {
pools,
prices,
pairs,
prettyPools
} = await getPoolsPricesPairs(rpcClient);
// const routes = lookupRoutesForTrade({
// pools,
// trade: {
// sell: {
// denom: tokenIn.denom,
// amount: tokenInAmount
// },
// buy: {
// denom: tokenOut.denom,
// amount: tokenOutAmount
// },
// beliefValue: value
// },
// pairs
// }).map((tradeRoute) => {
// const {
// poolId,
// tokenOutDenom
// } = tradeRoute;
// return {
// poolId,
// tokenOutDenom
// };
// });
// const OSMO_USDC_POOL_ID = 678;
// const ATOM_OSMO_POOL_ID = 1;
// async function getOsmosisUsdPrice () {
// const osmoUsd = await client.osmosis.gamm.v2.spotPrice({
// poolId: new Long(678),
// baseAssetDenom: "ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858",
// quoteAssetDenom: "uosmo"
// });
// return osmoUsd.spotPrice ?? null;
// }
// async function getAssetPoolPrice (poolId) {
// const response2 = await client.osmosis.gamm.v2.spotPrice({
// poolId: new Long(1),
// baseAssetDenom: "uosmo",
// quoteAssetDenom: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2"
// });
// }
// async function getPoolInfo (poolId) {
// const poolDetailsResponse = await client.osmosis.gamm.v1beta1.pool({
// poolId: new Long(poolId)
// });
// console.dir(poolDetailsResponse.pool.poolAssets);
// }
// function main () {
// console.log(pools);
// console.log(prices);
// }
// main();