Skip to content

Commit

Permalink
Implement WarpCore and Token classes (#3272)
Browse files Browse the repository at this point in the history
### Description

Implements the WarpCore and auxiliary classes.

Summary of changes:
- Add `WarpCore`, `Token`, and `TokenAmount` classes
- Define TokenStandard enum and TokenConnection type
- Improve IGP quote handling in token adapters
- Define `ChainNameOrId` type, also use in MultiProvider
- Add optional `denom` field to chain metadata native token

### Related issues

Fixes hyperlane-xyz/hyperlane-warp-ui-template#129

### Backward compatibility

No: The params to the `IHypTokenAdapter` `populateTransferRemoteTx` method have changed. `txValue` has been replaced with `interchainGas`

### Testing

- Created new tests
- Integrated into Warp UI
  • Loading branch information
jmrossy authored Feb 27, 2024
1 parent 65fa0da commit aea9e14
Show file tree
Hide file tree
Showing 38 changed files with 2,292 additions and 248 deletions.
8 changes: 8 additions & 0 deletions .changeset/lazy-guests-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@hyperlane-xyz/utils': minor
'@hyperlane-xyz/sdk': minor
---

Add `WarpCore`, `Token`, and `TokenAmount` classes for interacting with Warp Route instances.

_Breaking change_: The params to the `IHypTokenAdapter` `populateTransferRemoteTx` method have changed. `txValue` has been replaced with `interchainGas`.
2 changes: 1 addition & 1 deletion typescript/cli/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# motivation is to test both the bare bone deployment (included in the docs) and the deployment with the routing over igp hook (which is closer to production deployment)
HOOK_FLAG=$1
if [ -z "$HOOK_FLAG" ]; then
echo "Usage: fork.sh <hook>"
echo "Usage: ci-test.sh <hook>"
exit 1
fi

Expand Down
45 changes: 30 additions & 15 deletions typescript/cli/src/send/transfer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { input } from '@inquirer/prompts';
import { BigNumber, ethers } from 'ethers';
import { PopulatedTransaction, ethers } from 'ethers';

import {
ERC20__factory,
Expand All @@ -9,8 +9,11 @@ import {
import {
ChainName,
EvmHypCollateralAdapter,
EvmHypNativeAdapter,
EvmHypSyntheticAdapter,
HyperlaneContractsMap,
HyperlaneCore,
IHypTokenAdapter,
MultiProtocolProvider,
MultiProvider,
TokenType,
Expand Down Expand Up @@ -176,6 +179,9 @@ async function executeDelivery({
const provider = multiProvider.getProvider(origin);
const connectedSigner = signer.connect(provider);

// TODO replace all code below with WarpCore
// https://github.com/hyperlane-xyz/hyperlane-monorepo/issues/3259

if (tokenType === TokenType.collateral) {
const wrappedToken = await getWrappedToken(routerAddress, provider);
const token = ERC20__factory.connect(wrappedToken, connectedSigner);
Expand All @@ -186,24 +192,33 @@ async function executeDelivery({
}
}

// TODO move next section into MultiProtocolTokenApp when it exists
const adapter = new EvmHypCollateralAdapter(
origin,
MultiProtocolProvider.fromMultiProvider(multiProvider),
{ token: routerAddress },
);
let adapter: IHypTokenAdapter<PopulatedTransaction>;
const multiProtocolProvider =
MultiProtocolProvider.fromMultiProvider(multiProvider);
if (tokenType === TokenType.native) {
adapter = new EvmHypNativeAdapter(origin, multiProtocolProvider, {
token: routerAddress,
});
} else if (tokenType === TokenType.collateral) {
adapter = new EvmHypCollateralAdapter(origin, multiProtocolProvider, {
token: routerAddress,
});
} else {
adapter = new EvmHypSyntheticAdapter(origin, multiProtocolProvider, {
token: routerAddress,
});
}

const destinationDomain = multiProvider.getDomainId(destination);
const gasPayment = await adapter.quoteGasPayment(destinationDomain);
const txValue =
tokenType === TokenType.native
? BigNumber.from(gasPayment).add(wei).toString()
: gasPayment;
const transferTx = await adapter.populateTransferRemoteTx({
log('Fetching interchain gas quote');
const interchainGas = await adapter.quoteGasPayment(destinationDomain);
log('Interchain gas quote:', interchainGas);
const transferTx = (await adapter.populateTransferRemoteTx({
weiAmountOrId: wei,
destination: destinationDomain,
recipient,
txValue,
});
interchainGas,
})) as ethers.PopulatedTransaction;

const txResponse = await connectedSigner.sendTransaction(transferTx);
const txReceipt = await multiProvider.handleTx(origin, txResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ async function checkBalance(
);
}
case ProtocolType.Cosmos: {
if (!token.tokenAddress)
throw new Error('Token address missing for cosmos token');
const adapter = new CwNativeTokenAdapter(
chain,
multiProtocolProvider,
Expand Down
7 changes: 1 addition & 6 deletions typescript/sdk/logos/black/plume.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion typescript/sdk/logos/color/plume.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion typescript/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"prettier": "^2.8.8",
"sinon": "^13.0.2",
"ts-node": "^10.8.0",
"typescript": "5.1.6"
"typescript": "5.1.6",
"yaml": "^2.3.1"
},
"files": [
"/dist",
Expand Down
7 changes: 4 additions & 3 deletions typescript/sdk/src/consts/chainMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ export const injective: ChainMetadata = {
name: Chains.injective,
nativeToken: {
decimals: 18,
denom: 'inj',
name: 'Injective',
symbol: 'INJ',
},
Expand Down Expand Up @@ -612,6 +613,7 @@ export const neutron: ChainMetadata = {
name: Chains.neutron,
nativeToken: {
decimals: 6,
denom: 'untrn',
name: 'Neutron',
symbol: 'NTRN',
},
Expand Down Expand Up @@ -897,7 +899,6 @@ export const solana: ChainMetadata = {
url: 'https://explorer.solana.com',
},
],

blocks: {
confirmations: 1,
estimateBlockTime: 0.4,
Expand Down Expand Up @@ -1039,7 +1040,7 @@ export const viction: ChainMetadata = {
apiUrl: 'https://www.vicscan.xyz/api',
family: ExplorerFamily.Other,
name: 'Vicscan',
url: 'https://www.vicscan.xyz/',
url: 'https://www.vicscan.xyz',
},
],
blocks: {
Expand All @@ -1060,7 +1061,7 @@ export const viction: ChainMetadata = {
protocol: ProtocolType.Ethereum,
rpcUrls: [
{
http: 'https://rpc.tomochain.com/',
http: 'https://rpc.tomochain.com',
},
{
http: 'https://viction.blockpi.network/v1/rpc/public',
Expand Down
7 changes: 6 additions & 1 deletion typescript/sdk/src/gas/oracle/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export type StorageGasOracleConfig = Pick<
'gasPrice' | 'tokenExchangeRate'
>;

export const formatGasOracleConfig = (config: StorageGasOracleConfig) => ({
export const formatGasOracleConfig = (
config: StorageGasOracleConfig,
): {
tokenExchangeRate: string;
gasPrice: string;
} => ({
tokenExchangeRate: ethers.utils.formatUnits(
config.tokenExchangeRate,
TOKEN_EXCHANGE_RATE_EXPONENT,
Expand Down
42 changes: 37 additions & 5 deletions typescript/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ export {
OwnerViolation,
ViolationType,
} from './deploy/types';
export { PostDeploymentContractVerifier } from './deploy/verify/PostDeploymentContractVerifier';
export { ContractVerifier } from './deploy/verify/ContractVerifier';
export { PostDeploymentContractVerifier } from './deploy/verify/PostDeploymentContractVerifier';
export {
BuildArtifact,
CompilerOptions,
ContractVerificationInput,
VerificationInput,
ExplorerLicenseType,
BuildArtifact,
VerificationInput,
} from './deploy/verify/types';
export * as verificationUtils from './deploy/verify/utils';
export { HyperlaneIgp } from './gas/HyperlaneIgp';
Expand Down Expand Up @@ -136,7 +136,6 @@ export {
ProtocolFeeHookConfig,
} from './hook/types';
export { HyperlaneIsmFactory } from './ism/HyperlaneIsmFactory';
export { collectValidators, moduleCanCertainlyVerify } from './ism/utils';
export {
buildAggregationIsmConfigs,
buildMultisigIsmConfigs,
Expand All @@ -153,6 +152,7 @@ export {
PausableIsmConfig,
RoutingIsmConfig,
} from './ism/types';
export { collectValidators, moduleCanCertainlyVerify } from './ism/utils';
export {
ChainMetadataManager,
ChainMetadataManagerOptions,
Expand Down Expand Up @@ -322,6 +322,27 @@ export {
RouterViolationType,
proxiedFactories,
} from './router/types';
export { IToken, TokenArgs, TokenConfigSchema } from './token/IToken';
export { Token } from './token/Token';
export { TokenAmount } from './token/TokenAmount';
export {
HyperlaneTokenConnection,
IbcToHyperlaneTokenConnection,
IbcTokenConnection,
TokenConnection,
TokenConnectionConfigSchema,
TokenConnectionType,
} from './token/TokenConnection';
export {
PROTOCOL_TO_NATIVE_STANDARD,
TOKEN_COLLATERALIZED_STANDARDS,
TOKEN_COSMWASM_STANDARDS,
TOKEN_HYP_STANDARDS,
TOKEN_MULTI_CHAIN_STANDARDS,
TOKEN_NFT_STANDARDS,
TOKEN_STANDARD_TO_PROTOCOL,
TokenStandard,
} from './token/TokenStandard';
export {
CW20Metadata,
CwHypCollateralAdapter,
Expand All @@ -337,11 +358,13 @@ export {
} from './token/adapters/CosmosTokenAdapter';
export {
EvmHypCollateralAdapter,
EvmHypNativeAdapter,
EvmHypSyntheticAdapter,
EvmNativeTokenAdapter,
EvmTokenAdapter,
} from './token/adapters/EvmTokenAdapter';
export {
InterchainGasQuote as AdapterInterchainGasQuote,
IHypTokenAdapter,
ITokenAdapter,
TransferParams,
Expand Down Expand Up @@ -389,8 +412,8 @@ export { HypERC20Deployer, HypERC721Deployer } from './token/deploy';
export {
ChainMap,
ChainName,
ChainNameOrId,
Connection,
NameOrDomain,
TestChainNames,
} from './types';
export { MultiGeneric } from './utils/MultiGeneric';
Expand All @@ -402,3 +425,12 @@ export {
getSealevelAccountDataSchema,
} from './utils/sealevelSerialization';
export { chainMetadataToWagmiChain, wagmiChainMetadata } from './utils/wagmi';
export { WarpCore, WarpCoreOptions } from './warp/WarpCore';
export {
IgpQuoteConstants,
RouteBlacklist,
WarpCoreConfig,
WarpCoreConfigSchema,
WarpTxCategory,
WarpTypedTransaction,
} from './warp/types';
Loading

0 comments on commit aea9e14

Please sign in to comment.