Skip to content

Commit

Permalink
Tx fee estimatators and WarpCore interface refinements (#3364)
Browse files Browse the repository at this point in the history
### Description

- Add multi-protocol transaction fee estimators
- Improve WarpCore interface 
- Fix ChainMetadata `transactionOverrides` zod type

### Drive-by changes

Add `gasPrice` field to Neutron chain metadata

### Related issues

hyperlane-xyz/hyperlane-warp-ui-template#123

### Backward compatibility

Small breaking change: Token Adapter `quoteGasPayment` method renamed to `quoteTransferRemoteFee` for clarity.

### Testing

Tested in Warp UI with nexus routes.
  • Loading branch information
jmrossy authored Mar 12, 2024
1 parent 985adc9 commit 254466f
Show file tree
Hide file tree
Showing 18 changed files with 817 additions and 190 deletions.
6 changes: 6 additions & 0 deletions .changeset/chatty-seals-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hyperlane-xyz/sdk': minor
---

**New Feature**: Add transaction fee estimators to the SDK
**Breaking change**: Token Adapter `quoteGasPayment` method renamed to `quoteTransferRemoteGas` for clarity.
2 changes: 1 addition & 1 deletion typescript/cli/src/send/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async function executeDelivery({

const destinationDomain = multiProvider.getDomainId(destination);
log('Fetching interchain gas quote');
const interchainGas = await adapter.quoteGasPayment(destinationDomain);
const interchainGas = await adapter.quoteTransferRemoteGas(destinationDomain);
log('Interchain gas quote:', interchainGas);
const transferTx = (await adapter.populateTransferRemoteTx({
weiAmountOrId: wei,
Expand Down
3 changes: 3 additions & 0 deletions typescript/sdk/src/consts/chainMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,9 @@ export const neutron: ChainMetadata = {
restUrls: [{ http: 'https://rest-lb.neutron.org' }],
rpcUrls: [{ http: 'https://rpc-kralum.neutron-1.neutron.org' }],
slip44: 118,
transactionOverrides: {
gasPrice: '0.0075',
},
};

export const optimism: ChainMetadata = {
Expand Down
4 changes: 2 additions & 2 deletions typescript/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ export {
EvmTokenAdapter,
} from './token/adapters/EvmTokenAdapter';
export {
InterchainGasQuote as AdapterInterchainGasQuote,
IHypTokenAdapter,
ITokenAdapter,
InterchainGasQuote,
TransferParams,
TransferRemoteParams,
} from './token/adapters/ITokenAdapter';
Expand Down Expand Up @@ -432,7 +432,7 @@ export {
export { chainMetadataToWagmiChain, wagmiChainMetadata } from './utils/wagmi';
export { WarpCore, WarpCoreOptions } from './warp/WarpCore';
export {
IgpQuoteConstants,
FeeConstantConfig,
RouteBlacklist,
WarpCoreConfig,
WarpCoreConfigSchema,
Expand Down
2 changes: 1 addition & 1 deletion typescript/sdk/src/metadata/chainMetadataTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export const ChainMetadataSchemaObject = z.object({
.optional()
.describe('Block settings for the chain/deployment.'),
transactionOverrides: z
.object({})
.record(z.any())
.optional()
.describe('Properties to include when forming transaction requests.'),
gasCurrencyCoinGeckoId: z
Expand Down
35 changes: 34 additions & 1 deletion typescript/sdk/src/providers/MultiProtocolProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Debugger, debug } from 'debug';

import { objFilter, objMap, pick } from '@hyperlane-xyz/utils';
import {
Address,
HexString,
objFilter,
objMap,
pick,
} from '@hyperlane-xyz/utils';

import { chainMetadata as defaultChainMetadata } from '../consts/chainMetadata';
import { ChainMetadataManager } from '../metadata/ChainMetadataManager';
Expand All @@ -17,12 +23,17 @@ import {
ProviderType,
SolanaWeb3Provider,
TypedProvider,
TypedTransaction,
ViemProvider,
} from './ProviderType';
import {
ProviderBuilderMap,
defaultProviderBuilderMap,
} from './providerBuilders';
import {
TransactionFeeEstimate,
estimateTransactionFee,
} from './transactionFeeEstimators';

export interface MultiProtocolProviderOptions {
loggerName?: string;
Expand Down Expand Up @@ -208,6 +219,28 @@ export class MultiProtocolProvider<
}
}

estimateTransactionFee({
chainNameOrId,
transaction,
sender,
senderPubKey,
}: {
chainNameOrId: ChainNameOrId;
transaction: TypedTransaction;
sender: Address;
senderPubKey?: HexString;
}): Promise<TransactionFeeEstimate> {
const provider = this.getProvider(chainNameOrId, transaction.type);
const chainMetadata = this.getChainMetadata(chainNameOrId);
return estimateTransactionFee({
transaction,
provider,
chainMetadata,
sender,
senderPubKey,
});
}

override intersect(
chains: ChainName[],
throwIfNotSubset = false,
Expand Down
Loading

0 comments on commit 254466f

Please sign in to comment.