Add gas payments to kathy (#834)

pull/859/head
Asa Oines 2 years ago committed by GitHub
parent 1ece33d3c0
commit a46f724c64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      typescript/helloworld/src/app/app.ts
  2. 8
      typescript/infra/config/environments/mainnet/chains.ts
  3. 9
      typescript/infra/scripts/helloworld/kathy.ts
  4. 6
      typescript/sdk/src/gas/calculator.test.ts
  5. 5
      typescript/sdk/src/gas/calculator.ts

@ -1,4 +1,4 @@
import { ethers } from 'ethers'; import { BigNumber, ethers } from 'ethers';
import { TypedListener } from '@abacus-network/core/dist/common'; import { TypedListener } from '@abacus-network/core/dist/common';
import { import {
@ -19,6 +19,7 @@ export class HelloWorldApp<
from: From, from: From,
to: Remotes<Chain, From>, to: Remotes<Chain, From>,
message: string, message: string,
value: BigNumber,
receiveHandler?: TypedListener<ReceivedHelloWorldEvent>, receiveHandler?: TypedListener<ReceivedHelloWorldEvent>,
): Promise<ethers.ContractReceipt> { ): Promise<ethers.ContractReceipt> {
const sender = this.getContracts(from).router; const sender = this.getContracts(from).router;
@ -29,14 +30,16 @@ export class HelloWorldApp<
const estimated = await sender.estimateGas.sendHelloWorld( const estimated = await sender.estimateGas.sendHelloWorld(
toDomain, toDomain,
message, message,
chainConnection.overrides, { ...chainConnection.overrides, value },
); );
const gasLimit = estimated.mul(12).div(10); const gasLimit = estimated.mul(12).div(10);
const tx = await sender.sendHelloWorld(toDomain, message, { const tx = await sender.sendHelloWorld(toDomain, message, {
...chainConnection.overrides, ...chainConnection.overrides,
gasLimit, gasLimit,
value,
}); });
console.log(tx);
const receipt = await tx.wait(chainConnection.confirmations); const receipt = await tx.wait(chainConnection.confirmations);
if (receiveHandler) { if (receiveHandler) {

@ -8,7 +8,7 @@ export const mainnetConfigs: ChainMap<any, IChainConnection> = {
bsc: { bsc: {
...chainConnectionConfigs.bsc, ...chainConnectionConfigs.bsc,
overrides: { overrides: {
gasPrice: 7 * 10 ** 9, gasPrice: 7 * 10 ** 9, // 7 gwei
}, },
}, },
avalanche: chainConnectionConfigs.avalanche, avalanche: chainConnectionConfigs.avalanche,
@ -16,9 +16,9 @@ export const mainnetConfigs: ChainMap<any, IChainConnection> = {
...chainConnectionConfigs.polygon, ...chainConnectionConfigs.polygon,
confirmations: 3, confirmations: 3,
overrides: { overrides: {
maxFeePerGas: 100 * 10 ** 9, // gwei maxFeePerGas: 100 * 10 ** 9, // 100 gwei
maxPriorityFeePerGas: 40 * 10 ** 9, // gwei maxPriorityFeePerGas: 40 * 10 ** 9, // 40 gwei
// gasPrice: 50 * 10 ** 9, // gwei // gasPrice: 50 * 10 ** 9, // 50 gwei
}, },
}, },
celo: chainConnectionConfigs.celo, celo: chainConnectionConfigs.celo,

@ -1,3 +1,4 @@
import { BigNumber } from 'ethers';
import { Gauge, Registry } from 'prom-client'; import { Gauge, Registry } from 'prom-client';
import { HelloWorldApp } from '@abacus-network/helloworld'; import { HelloWorldApp } from '@abacus-network/helloworld';
@ -106,8 +107,14 @@ async function sendMessage(
gasCalc: InterchainGasCalculator<any>, gasCalc: InterchainGasCalculator<any>,
) { ) {
const msg = 'Hello!'; const msg = 'Hello!';
const expectedHandleGas = BigNumber.from(100_000);
const value = await gasCalc.estimatePaymentForHandleGas(
origin,
destination,
expectedHandleGas,
);
console.log(`Sending message from ${origin} to ${destination}`); console.log(`Sending message from ${origin} to ${destination}`);
const receipt = await app.sendHelloWorld(origin, destination, msg); const receipt = await app.sendHelloWorld(origin, destination, msg, value);
console.log(JSON.stringify(receipt.events || receipt.logs)); console.log(JSON.stringify(receipt.events || receipt.logs));
} }

@ -1,9 +1,7 @@
import { expect } from 'chai'; import { expect } from 'chai';
import { BigNumber, ethers } from 'ethers'; import { BigNumber } from 'ethers';
import sinon from 'sinon'; import sinon from 'sinon';
import { utils } from '@abacus-network/utils';
import { Chains } from '../consts/chains'; import { Chains } from '../consts/chains';
import { AbacusCore } from '../core/AbacusCore'; import { AbacusCore } from '../core/AbacusCore';
import { CoreContracts } from '../core/contracts'; import { CoreContracts } from '../core/contracts';
@ -129,6 +127,7 @@ describe('InterchainGasCalculator', () => {
}); });
}); });
/*
describe('estimatePaymentForMessage', () => { describe('estimatePaymentForMessage', () => {
it('estimates origin token payment from a specified message', async () => { it('estimates origin token payment from a specified message', async () => {
// Set destination gas price to 10 wei // Set destination gas price to 10 wei
@ -165,6 +164,7 @@ describe('InterchainGasCalculator', () => {
expect(estimatedPayment.toNumber()).to.equal(1_000_000); expect(estimatedPayment.toNumber()).to.equal(1_000_000);
}); });
}); });
*/
describe('convertBetweenTokens', () => { describe('convertBetweenTokens', () => {
const destinationWei = BigNumber.from('1000'); const destinationWei = BigNumber.from('1000');

@ -184,12 +184,13 @@ export class InterchainGasCalculator<Chain extends ChainName> {
* denominated in the native token of the origin chain. The gas used by the message's * denominated in the native token of the origin chain. The gas used by the message's
* recipient handler function is estimated in an eth_estimateGas call to the * recipient handler function is estimated in an eth_estimateGas call to the
* destination chain, and is then used to calculate the payment using * destination chain, and is then used to calculate the payment using
* Currently made private as it does not work properly for Arbitrum.
* {@link estimatePaymentForHandleGasAmount}. * {@link estimatePaymentForHandleGasAmount}.
* @param message The parsed message to estimate payment for. * @param message The parsed message to estimate payment for.
* @returns An estimated amount of origin chain tokens to cover gas costs of the * @returns An estimated amount of origin chain tokens to cover gas costs of the
* message on the destination chain. * message on the destination chain.
*/ */
async estimatePaymentForMessage<Destination extends Chain>( protected async estimatePaymentForMessage<Destination extends Chain>(
message: ParsedMessage<Chain, Destination>, message: ParsedMessage<Chain, Destination>,
): Promise<BigNumber> { ): Promise<BigNumber> {
const handleGas = await this.estimateGasForHandle(message); const handleGas = await this.estimateGasForHandle(message);
@ -289,7 +290,7 @@ export class InterchainGasCalculator<Chain extends ChainName> {
from: destinationInbox.address, from: destinationInbox.address,
data: handlerInterface.encodeFunctionData('handle', [ data: handlerInterface.encodeFunctionData('handle', [
chainMetadata[message.origin].id, chainMetadata[message.origin].id,
message.sender, utils.addressToBytes32(message.sender),
message.body, message.body,
]), ]),
}); });

Loading…
Cancel
Save