diff --git a/README.md b/README.md index b741578a..6d901d11 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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. @@ -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` @@ -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 diff --git a/deploy.yml b/deploy.yml index 72a09426..25c87fa3 100644 --- a/deploy.yml +++ b/deploy.yml @@ -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: diff --git a/scripts/autostake.mjs b/scripts/autostake.mjs index 956a6ed6..8d826db1 100644 --- a/scripts/autostake.mjs +++ b/scripts/autostake.mjs @@ -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) diff --git a/src/components/ClaimRewards.js b/src/components/ClaimRewards.js index f4dc36f5..1b5cd87a 100644 --- a/src/components/ClaimRewards.js +++ b/src/components/ClaimRewards.js @@ -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 @@ -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) => { diff --git a/src/components/DelegateForm.js b/src/components/DelegateForm.js index dc0f5e54..aa24a913 100644 --- a/src/components/DelegateForm.js +++ b/src/components/DelegateForm.js @@ -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); @@ -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{ @@ -74,7 +80,7 @@ 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), } }) } @@ -82,6 +88,7 @@ class DelegateForm extends React.Component { } 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 diff --git a/src/networks.json b/src/networks.json index 015d142b..a660ad0f 100644 --- a/src/networks.json +++ b/src/networks.json @@ -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", diff --git a/src/utils/SigningClient.mjs b/src/utils/SigningClient.mjs index 51f36db1..75d415aa 100644 --- a/src/utils/SigningClient.mjs +++ b/src/utils/SigningClient.mjs @@ -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); } @@ -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){