Skip to content

Commit

Permalink
Merge pull request #54 from eco-stake/bugs-and-tweaks
Browse files Browse the repository at this point in the history
Bugs and tweaks
  • Loading branch information
tombeynon authored Mar 5, 2022
2 parents a0b67a1 + d19adeb commit 748f580
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 37 deletions.
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,19 @@ You only need a single mnemonic for multiple Cosmos chains, and the script will

### Setup the autostaking script and run daily

You can run the autostaking script using `docker-compose` or using `npm` directly. In both cases you will need to provide your mnemonic in a `MNEMONIC` environment variable. Instructions are provided for Docker Compose and will be expanded later.
You can run the autostaking script using `docker-compose` or using `npm` directly. In both cases you will need to provide your mnemonic in a `MNEMONIC` environment variable.

Instructions are provided for Docker Compose and will be expanded later.

### Install Docker and Docker Compose

Best bet is to follow the Docker official guides. Install Docker first, then Docker Compose.

Docker: [docs.docker.com/get-docker](https://docs.docker.com/get-docker/)

Docker Compose: [docs.docker.com/compose/install](https://docs.docker.com/compose/install/)

### Clone the repository and setup .env

Clone the repository and copy the sample `.env` file ready for your mnemonic.

Expand All @@ -46,12 +58,6 @@ cp .env.sample .env

**Populate your new .env file with your mnemonic.**

### Install Docker Compose

```
sudo apt install docker
```

### Running the script (to see if everything works correctly)

Running the autostake script manually is then simple.
Expand All @@ -68,6 +74,17 @@ Pass a network name to run the script for a single network at a time.
docker-compose run app npm run autostake osmosis
```

### Updating your local version

REStake is MVP. Very MVP. Updates are happening all the time and there are bugs that still need fixing. Make sure you update often.

Update your local repository and pre-build your Docker containers with the following commands:

```
git pull
docker-compose build
```

### Setting up Cron to make sure the script runs daily

You should setup your script to run at the same time each day using `crontab`
Expand All @@ -78,7 +95,7 @@ crontab -e
0 21 * * * /bin/bash -c "cd restake && docker-compose run app npm run autostake" > ./restake.log 2>&1
```

Use `git pull` to retrieve the latest version as required. The autostaking script can and will change in the near future.
Don't forget to [update often](#updating-your-local-version)!

## Submiting your operator

Expand Down
5 changes: 3 additions & 2 deletions deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ services:
image: ghcr.io/eco-stake/restake:latest
expose:
- port: 80
to:
- global: true
accept:
- restake.ecostake.com
- restake.app
to:
- global: true

profiles:
compute:
Expand Down
4 changes: 3 additions & 1 deletion scripts/autostake.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ class Autostake {
console.log(data.prettyName, 'bot address is', botAddress)

const client = await network.signingClient(wallet)
client.registry.register("/cosmos.authz.v1beta1.MsgExec", MsgExec)
if(client.connected){
client.registry.register("/cosmos.authz.v1beta1.MsgExec", MsgExec)
}

const operatorData = data.operators.find(el => el.botAddress === botAddress)
const operator = operatorData && Operator(operatorData)
Expand Down
16 changes: 14 additions & 2 deletions src/components/ClaimRewards.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ function ClaimRewards(props) {
if(props.restake && perValidatorReward > 0){
let messages = buildMessages(props.validators, perValidatorReward)

gas = await props.stargateClient.simulate(props.address, messages)
try {
gas = await props.stargateClient.simulate(props.address, messages)
} catch (error) {
props.setLoading(false)
props.setError('Failed to broadcast: ' + error.message)
return
}

const fee = props.stargateClient.getFee(gas)
const feeAmount = fee.amount[0].amount
Expand All @@ -38,7 +44,13 @@ function ClaimRewards(props) {
return
}
let messages = buildMessages(props.validators, perValidatorReward)
gas = gas || await props.stargateClient.simulate(props.address, messages)
try {
gas = gas || await props.stargateClient.simulate(props.address, messages)
} catch (error) {
props.setLoading(false)
props.setError('Failed to broadcast: ' + error.message)
return
}
console.log(messages, gas)

signAndBroadcast(props.address, messages, gas).then((result) => {
Expand Down
13 changes: 10 additions & 3 deletions src/components/DelegateForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ class DelegateForm extends React.Component {
const client = this.props.stargateClient

let messages = this.buildMessages(amount)
const gas = await client.simulate(this.props.address, messages)
let gas
try {
gas = await client.simulate(this.props.address, messages)
} catch (error) {
this.setState({ loading: false, error: error.message })
return
}

client.signAndBroadcast(address, messages, gas, memo).then((result) => {
console.log("Successfully broadcasted:", result);
Expand All @@ -64,7 +70,7 @@ class DelegateForm extends React.Component {
delegatorAddress: address,
validatorSrcAddress: this.props.validator.operator_address,
validatorDstAddress: validatorAddress,
amount: coin(parseFloat(amount) * 1000000, this.props.network.denom),
amount: coin(parseInt(parseFloat(amount) * 1000000), this.props.network.denom),
}
})
}else{
Expand All @@ -74,14 +80,15 @@ class DelegateForm extends React.Component {
value: {
delegatorAddress: address,
validatorAddress: validatorAddress,
amount: coin(parseFloat(amount) * 1000000, this.props.network.denom),
amount: coin(parseInt(parseFloat(amount) * 1000000), this.props.network.denom),
}
})
}
return messages
}

async setAvailableAmount(){
this.setState({error: undefined})
const messages = this.buildMessages(parseInt(this.props.availableBalance.amount * 0.95) / 1_000_000.0)
this.props.stargateClient.simulate(this.props.address, messages).then(gas => {
const saveTxFeeNum = (this.props.redelegate || this.props.undelegate) ? 0 : 10
Expand Down
2 changes: 1 addition & 1 deletion src/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@
],
"image": "https://raw.githubusercontent.com/osmosis-labs/assetlists/main/images/luna.svg",
"testAddress": "terra1rnszu7kumz5lmgdk3fv2pmzt3s8vhcddqep7d4",
"gasPrice": "170ukrw",
"gasPrice": "0.015uluna",
"operators": [
{
"address": "terravaloper1f2t96sz9hnwsqnneux6v28xfgn07pkxjduvwjz",
Expand Down
41 changes: 21 additions & 20 deletions src/utils/SigningClient.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const SigningClient = async (rpcUrl, chainId, defaultGasPrice, signer, key) => {
const getFee = (gas, gasPrice) => {
if(!gas) gas = 200_000
if(!gasPrice) gasPrice = GasPrice.fromString(defaultGasPrice);
console.log(gas, gasPrice, defaultGasPrice)
return calculateFee(gas, gasPrice);
}

Expand All @@ -46,31 +47,31 @@ const SigningClient = async (rpcUrl, chainId, defaultGasPrice, signer, key) => {
}

const signAndBroadcast = async (address, msgs, gas, memo, gasPrice) => {
if(!gas) gas = await simulate(address, msgs, memo)
const fee = getFee(gas, gasPrice)

return new Promise((success, reject) => {
client.signAndBroadcast(address, msgs, fee, memo).then((result) => {
try {
assertIsDeliverTxSuccess(result);
client.disconnect();
success(result)
} catch (error) {
reject(error)
}
}, (error) => {
return new Promise(async (success, reject) => {
let fee
try {
if(!gas) gas = await simulate(address, msgs, memo)
fee = getFee(gas, gasPrice)
} catch (error) {
return reject(error)
}
client.signAndBroadcast(address, msgs, fee, memo).then((result) => {
try {
assertIsDeliverTxSuccess(result);
client.disconnect();
success(result)
} catch (error) {
reject(error)
})
}
}, (error) => {
reject(error)
})
});
}

const simulate = async (address, msgs, memo, modifier) => {
try{
const estimate = await client.simulate(address, msgs, memo)
return (parseInt(estimate * (modifier || 1.5)))
}catch (error){
return undefined
}
const estimate = await client.simulate(address, msgs, memo)
return (parseInt(estimate * (modifier || 1.5)))
}

function findAvailableUrl(urls){
Expand Down

0 comments on commit 748f580

Please sign in to comment.