Skip to content
This repository has been archived by the owner on Dec 25, 2024. It is now read-only.

Commit

Permalink
Add osmosis deposit module
Browse files Browse the repository at this point in the history
  • Loading branch information
atmoner committed Aug 30, 2022
1 parent c008e53 commit 8bc40fd
Show file tree
Hide file tree
Showing 5 changed files with 6,578 additions and 6 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
"install:simple-send": "cd scripts/simple-send/ && npm install",
"install:withdraw-rewards": "cd scripts/withdraw-rewards/ && npm install",
"install:validator-commisions": "cd scripts/validator-commisions/ && npm install",
"install:osmosis-deposit": "cd scripts/osmosis-deposit/ && npm install",
"install:create-account": "node createAccount.js",
"clear:get-price": "cd scripts/get-price/ && rm -Rf node_modules/",
"clear:simple-send": "cd scripts/simple-send/ && rm -Rf node_modules/",
"clear:withdraw-rewards": "cd scripts/withdraw-rewards/ && rm -Rf node_modules/",
"clear:validator-commisions": "cd scripts/validator-commisions/ && rm -Rf node_modules/",
"clear:osmosis-deposit": "cd scripts/osmosis-deposit/ && rm -Rf node_modules/",
"clear:create-account": "> auth.config.js",
"postinstall": "run-p install:*",
"clear": "run-p clear:*"
Expand Down
19 changes: 13 additions & 6 deletions scripts/config.modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default [
script: './scripts/timer/app.js',
type: 'prod',
auth: false,
useChain: 'all',
notice: '',
variable: {
0: 'Cosmos_var1',
Expand All @@ -17,6 +18,7 @@ export default [
script: './scripts/get-price/app.js',
type: 'prod',
auth: false,
useChain: 'all',
notice: '',
variable: {
},
Expand All @@ -27,6 +29,7 @@ export default [
script: './scripts/simple-send/app.js',
type: 'prod',
auth: true,
useChain: 'all',
notice: '',
variable: {
0: 'sendTo',
Expand All @@ -39,6 +42,7 @@ export default [
script: './scripts/withdraw-rewards/app.js',
type: 'prod',
auth: true,
useChain: 'all',
notice: '',
variable: {
0: 'FromValidator'
Expand All @@ -48,21 +52,24 @@ export default [
name: 'Validator-commisions',
desc: '<h3>Validator commisions</h3> This module allows you to recover your validator commissions, if you are not a validator, the script will not work',
script: './scripts/validator-commisions/app.js',
type: 'dev',
type: 'prod',
auth: true,
useChain: ['BitCanna', 'Osmosis', 'Cosmoshub', 'Akash', 'Stargaze'],
notice: 'You must be a validator to run this script, otherwise it won\'t work!',
variable: {
},
}/*,
},
{
name: 'Reinvest-delegations',
desc: '<h3>Reinvest delegations</h3> This module allows you to reinvest the rewards of each delegation to the validator',
script: './scripts/reinvest-delegations/app.js',
name: 'Osmosis-deposit',
desc: '<h3>Osmosis deposit</h3> This module allows you to make a deposit from any chain to osmosis dex in an automated way',
script: './scripts/osmosis-deposit/app.js',
type: 'dev',
auth: true,
useChain: ['BitCanna', 'Cosmoshub', 'Akash', 'Stargaze'],
notice: '',
variable: {
0: 'amount'
},
}*/
}
]

84 changes: 84 additions & 0 deletions scripts/osmosis-deposit/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import pm2 from 'pm2'
import dayjs from 'dayjs'
import fs from "fs"
import { bech32 } from "bech32"
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"
import { chain, assets, asset_list, testnet, testnet_assets } from '@chain-registry/osmosis';
import { assertIsDeliverTxSuccess, SigningStargateClient, StargateClient, defaultRegistryTypes } from "@cosmjs/stargate"
import Long from "long";
import cosmosConfig from '../../cosmos.config.js'

// Dont remove this part!
function processWork(returnData) {
//do Stuff here

let today = dayjs();
var timestamp = today.format( "YYYY-MM-DD HH:mm:ss" )
console.log( '[' + timestamp + '] ' + returnData )
pm2.restart({
name : process.env.name,
env: {
"COSMOS_LAST_UPDATE": timestamp
}
}, (err, proc) => {
// Disconnects from PM2
pm2.disconnect()
})
}

function convertAddr(addr, toPrefix) {
var decode = bech32.decode(addr)
var newAddr = bech32.encode(toPrefix, decode.words)
return newAddr
}

async function doStuff() {

let buff = Buffer.from(process.env.COSMOS_PASS, 'base64')
let secret = buff.toString('ascii')

let finalWallet = fs.readFileSync('wallets/' + process.env.COSMOS_WALLET + '.json')
let foundChain = cosmosConfig.find(element => element.coinLookup.viewDenom === process.env.COSMOS_CHAIN)
let finalWalletData = JSON.parse(finalWallet)
var finalWalletDecode = await DirectSecp256k1HdWallet.deserialize(JSON.stringify(finalWalletData.data), secret)

const wallet = await DirectSecp256k1HdWallet.fromMnemonic(finalWalletDecode.secret.data, {
prefix: foundChain.coinLookup.addressPrefix
});
const [firstAccount] = await wallet.getAccounts()
const osmoAddr = convertAddr(firstAccount.address, 'osmo')
const rpcEndpoint = foundChain.rpcURL
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet)

const amount = {
denom: foundChain.coinLookup.chainDenom,
amount: process.env.amount / 1000000,
}
const fee = {
amount: [{
denom: foundChain.coinLookup.chainDenom,
amount: foundChain.fee.amount,
}],
gas: foundChain.fee.gas,
}

const result = await client.sendIbcTokens(
firstAccount.address,
osmoAddr,
amount,
"transfer",
foundChain.osmoIbc.channel,
{
revisionHeight: Long.fromNumber(0),
revisionNumber: Long.fromNumber(0)
},
Math.floor(Date.now() / 1000) + 60,
fee,
""
)
assertIsDeliverTxSuccess(result)

processWork('Tx hash: ' + result.transactionHash)
}
setInterval(doStuff, process.env.COSMOS_TIMER) // time is in ms

Loading

0 comments on commit 8bc40fd

Please sign in to comment.