Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: classic gas issues #103

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions eth/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion eth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.16.0",
"@terra-money/terra.js": "^3.0.0",
"@terra-money/terra.js": "3.1.9",
"axios": "^0.26.1",
"bech32": "^2.0.0",
"bignumber.js": "^9.0.1",
Expand Down
32 changes: 25 additions & 7 deletions eth/src/Relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
Coin,
Tx,
TxInfo,
Fee,
Coins,
} from '@terra-money/terra.js';
import { MonitoringData } from 'Monitoring';
import axios from 'axios';
Expand All @@ -32,6 +34,12 @@ const TERRA_GAS_PRICE_END_POINT = process.env
const TERRA_GAS_PRICE_DENOM = process.env.TERRA_GAS_PRICE_DENOM as string;
const TERRA_GAS_ADJUSTMENT = process.env.TERRA_GAS_ADJUSTMENT as string;
const TERRA_DONATION = process.env.TERRA_DONATION as string;
const TERRA_TAX_RATE = parseFloat(
(process.env.TERRA_TAX_RATE as string) || '0'
);
const TERRA_SEND_GAS = parseInt(
(process.env.TERRA_SEND_GAS as string) || '1000000'
);

export interface RelayDataRaw {
tx: string;
Expand All @@ -56,6 +64,7 @@ export class Relayer {
chainID: TERRA_CHAIN_ID,
gasPrices: TERRA_GAS_PRICE,
gasAdjustment: TERRA_GAS_ADJUSTMENT,
isClassic: false,
});

this.Wallet = new Wallet(
Expand All @@ -72,6 +81,7 @@ export class Relayer {
monitoringDatas: MonitoringData[],
sequence: number
): Promise<RelayData | null> {
let amount, denom;
const msgs: Msg[] = monitoringDatas.reduce(
(msgs: Msg[], data: MonitoringData) => {
const fromAddr = this.Wallet.key.accAddress;
Expand All @@ -86,11 +96,11 @@ export class Relayer {
return msgs;
}

const amount = data.amount.slice(0, data.amount.length - 12);
amount = data.amount.slice(0, data.amount.length - 12);
const info = data.terraAssetInfo;

if (info.denom) {
const denom = info.denom;
denom = info.denom;

msgs.push(new MsgSend(fromAddr, toAddr, [new Coin(denom, amount)]));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not deducting tax from the sent amount which means that the shuttle wallet will pay it, i.e. pay more than the equivalent of burnt wrapped tokens.

} else if (info.contract_address && !info.is_eth_asset) {
Expand Down Expand Up @@ -137,15 +147,23 @@ export class Relayer {
}

// if something wrong, pass undefined to use default gas
const gasPrices = await this.loadGasPrice(
TERRA_GAS_PRICE_END_POINT,
TERRA_GAS_PRICE_DENOM
).catch(() => undefined);
// const gasPrices = await this.loadGasPrice(
// TERRA_GAS_PRICE_END_POINT,
// TERRA_GAS_PRICE_DENOM
// ).catch(() => undefined);

let fees = Coins.fromString(TERRA_GAS_PRICE)
.mul(TERRA_SEND_GAS)
.toIntCeilCoins();
const tax = new Coins([new Coin(denom, amount)])
.mul(TERRA_TAX_RATE)
.toIntCeilCoins();
fees = fees.add(tax);

const tx = await this.Wallet.createAndSignTx({
msgs,
sequence,
gasPrices,
fee: new Fee(TERRA_SEND_GAS, fees),
});

const txHash = await this.LCDClient.tx.hash(tx);
Expand Down
Loading