Skip to content

Commit

Permalink
sdk changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aroralanuk committed Dec 23, 2023
1 parent 0e60c22 commit 90959ae
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 8 deletions.
5 changes: 3 additions & 2 deletions typescript/sdk/src/gas/HyperlaneIgpChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ export class HyperlaneIgpChecker extends HyperlaneAppChecker<

const remotes = this.app.remoteChains(local);
for (const remote of remotes) {
let expectedOverhead = this.configMap[local].overhead[remote];
let expectedOverhead =
this.configMap[local].oracleConfig[remote].overhead;
if (!expectedOverhead) {
this.app.logger(
`No overhead configured for ${local} -> ${remote}, defaulting to 0`,
);
expectedOverhead = 0;
expectedOverhead = BigNumber.from(0);
}

const remoteId = this.multiProvider.getDomainId(remote);
Expand Down
69 changes: 64 additions & 5 deletions typescript/sdk/src/gas/HyperlaneIgpDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import {
InterchainGasPaymaster,
ProxyAdmin,
StorageGasOracle,
StorageGasOracle__factory,
} from '@hyperlane-xyz/core';
import { eqAddress } from '@hyperlane-xyz/utils';
import { Address, eqAddress } from '@hyperlane-xyz/utils';

import { HyperlaneContracts } from '../contracts/types';
import { HyperlaneDeployer } from '../deploy/HyperlaneDeployer';
import { MultiProvider } from '../providers/MultiProvider';
import { ChainName } from '../types';
import { ChainMap, ChainName } from '../types';

import { IgpFactories, igpFactories } from './contracts';
import { IgpConfig } from './types';
import { DomainGasConfig, IgpConfig } from './types';

export class HyperlaneIgpDeployer extends HyperlaneDeployer<
IgpConfig,
Expand Down Expand Up @@ -42,10 +43,10 @@ export class HyperlaneIgpDeployer extends HyperlaneDeployer<
);

const gasParamsToSet: InterchainGasPaymaster.GasParamStruct[] = [];
const remotes = Object.keys(config.gasOracleType);
const remotes = Object.keys(config.oracleConfig);
for (const remote of remotes) {
const remoteId = this.multiProvider.getDomainId(remote);
const newGasOverhead = config.overhead[remote];
const newGasOverhead = config.oracleConfig[remote].overhead;

const currentGasConfig = await igp.destinationGasConfigs(remoteId);
if (
Expand Down Expand Up @@ -81,6 +82,64 @@ export class HyperlaneIgpDeployer extends HyperlaneDeployer<
return this.deployContract(chain, 'storageGasOracle', []);
}

async configureStorageGasOracle(
chain: ChainName,
igp: InterchainGasPaymaster,
gasOracleConfig: ChainMap<DomainGasConfig>,
): Promise<void> {
const remotes = Object.keys(gasOracleConfig);
const configsToSet: Record<
Address,
StorageGasOracle.RemoteGasDataConfigStruct[]
> = {};
for (const remote of remotes) {
const gasOracleAddress = (await igp.destinationGasConfigs(remote))
.gasOracle;
const gasOracle = StorageGasOracle__factory.connect(
gasOracleAddress,
this.multiProvider.getProvider(chain),
);
const remoteGasDataConfig = await gasOracle.remoteGasData(remote);
const desiredGasData = gasOracleConfig[remote];

if (
!remoteGasDataConfig.gasPrice.eq(desiredGasData.gasPrice) ||
!remoteGasDataConfig.tokenExchangeRate.eq(
desiredGasData.tokenExchangeRate,
)
) {
configsToSet[gasOracleAddress].push({
remoteDomain: this.multiProvider.getDomainId(remote),
...desiredGasData,
});
}
}

const gasOracles = Object.keys(configsToSet);
for (const gasOracle of gasOracles) {
const gasOracleContract = StorageGasOracle__factory.connect(
gasOracle,
this.multiProvider.getProvider(chain),
);
if (configsToSet[gasOracle].length > 0) {
this.logger(
`Setting gas oracle on ${gasOracle} for ${configsToSet[gasOracle].map(
(config) => config.remoteDomain,
)}`,
);
await this.runIfOwner(chain, gasOracleContract, async () =>
this.multiProvider.handleTx(
chain,
gasOracleContract.setRemoteGasDataConfigs(
configsToSet[gasOracle],
this.multiProvider.getTransactionOverrides(chain),
),
),
);
}
}
}

async deployContracts(
chain: ChainName,
config: IgpConfig,
Expand Down
12 changes: 11 additions & 1 deletion typescript/sdk/src/gas/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@ export enum GasOracleContractType {
StorageGasOracle = 'StorageGasOracle',
}

export type RemoteGasData = {
tokenExchangeRate: BigNumber;
gasPrice: BigNumber;
};

export type DomainGasConfig = RemoteGasData & {
type: GasOracleContractType;
overhead: BigNumber;
};

export type IgpConfig = {
owner: Address;
beneficiary: Address;
gasOracleType: ChainMap<GasOracleContractType>;
oracleKey: Address;
overhead: ChainMap<number>;
oracleConfig: ChainMap<DomainGasConfig>;
};

export enum IgpViolationType {
Expand Down

0 comments on commit 90959ae

Please sign in to comment.