Integrate the InterchainGasCalculator into Kathy (#818)

pull/821/head
Asa Oines 2 years ago committed by GitHub
parent a8d5d0bd56
commit 889c16a479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      typescript/helloworld/src/app/app.ts
  2. 39
      typescript/infra/scripts/helloworld/kathy.ts
  3. 15
      typescript/sdk/src/gas/calculator.ts
  4. 2
      typescript/sdk/src/index.ts

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

@ -1,7 +1,11 @@
import { Gauge, Registry } from 'prom-client';
import { HelloWorldApp } from '@abacus-network/helloworld';
import { ChainName, Chains } from '@abacus-network/sdk';
import {
ChainName,
Chains,
InterchainGasCalculator,
} from '@abacus-network/sdk';
import { submitMetrics } from '../../src/utils/metrics';
import { sleep } from '../../src/utils/utils';
@ -33,6 +37,11 @@ async function main() {
constMetricLabels.abacus_deployment = environment;
const coreConfig = getCoreEnvironmentConfig(environment);
const app = await getApp(coreConfig);
const multiProvider = await coreConfig.getMultiProvider();
const gasCalc = InterchainGasCalculator.fromEnvironment(
environment,
multiProvider as any,
);
const chains = app.chains() as Chains[];
const skip = process.env.CHAINS_TO_SKIP?.split(',').filter(
(skipChain) => skipChain.length > 0,
@ -47,7 +56,7 @@ async function main() {
let failureOccurred = false;
const sources = chains.filter((chain) => !skip || !skip.includes(chain));
const origins = chains.filter((chain) => !skip || !skip.includes(chain));
// submit frequently so we don't have to wait a super long time for info to get into the metrics
const metricsInterval = setInterval(() => {
@ -56,19 +65,19 @@ async function main() {
);
}, 1000 * 30);
for (const source of sources) {
for (const destination of sources.filter((d) => d !== source)) {
for (const origin of origins) {
for (const destination of origins.filter((d) => d !== origin)) {
const labels = {
origin: source,
origin,
remote: destination,
...constMetricLabels,
};
try {
await sendMessage(app, source, destination);
await sendMessage(app, origin, destination, gasCalc);
messagesSendStatus.labels({ ...labels }).set(1);
} catch (err) {
console.error(
`Error sending message from ${source} to ${destination}, continuing...`,
`Error sending message from ${origin} to ${destination}, continuing...`,
`${err}`.replaceAll('\n', ' ## '),
);
failureOccurred = true;
@ -92,11 +101,21 @@ async function main() {
async function sendMessage(
app: HelloWorldApp<any>,
source: ChainName,
origin: ChainName,
destination: ChainName,
gasCalc: InterchainGasCalculator<any>,
) {
console.log(`Sending message from ${source} to ${destination}`);
const receipt = await app.sendHelloWorld(source, destination, `Hello!`);
const msg = 'Hello!';
const expected = {
origin,
destination,
sender: app.getContracts(origin).router.address,
recipient: app.getContracts(destination).router.address,
body: msg,
};
const value = await gasCalc.estimatePaymentForMessage(expected);
console.log(`Sending message from ${origin} to ${destination}`);
const receipt = await app.sendHelloWorld(origin, destination, msg, value);
console.log(JSON.stringify(receipt.events || receipt.logs));
}

@ -4,7 +4,11 @@ import { BigNumber, FixedNumber, ethers } from 'ethers';
import { utils } from '@abacus-network/utils';
import { chainMetadata } from '../consts/chainMetadata';
import { AbacusCore } from '../core/AbacusCore';
import {
AbacusCore,
CoreEnvironment,
CoreEnvironmentChain,
} from '../core/AbacusCore';
import { MultiProvider } from '../providers/MultiProvider';
import { ChainName, Remotes } from '../types';
import { convertDecimalValue, mulBigAndFixed } from '../utils/number';
@ -86,6 +90,15 @@ export class InterchainGasCalculator<Chain extends ChainName> {
private paymentEstimateMultiplier: ethers.FixedNumber;
private messageGasEstimateBuffer: ethers.BigNumber;
static fromEnvironment<Env extends CoreEnvironment>(
env: Env,
multiProvider: MultiProvider<CoreEnvironmentChain<Env>>,
config?: InterchainGasCalculatorConfig,
): InterchainGasCalculator<CoreEnvironmentChain<Env>> {
const core = AbacusCore.fromEnvironment(env, multiProvider);
return new InterchainGasCalculator(multiProvider, core, config);
}
constructor(
multiProvider: MultiProvider<Chain>,
core: AbacusCore<Chain>,

@ -71,7 +71,7 @@ export {
} from './core/TestCoreApp';
export { TestCoreDeployer } from './core/TestCoreDeployer';
export { InterchainGasCalculator } from './gas/calculator';
export { InterchainGasCalculator, ParsedMessage } from './gas/calculator';
export {
CoinGeckoTokenPriceGetter,
TokenPriceGetter,

Loading…
Cancel
Save