Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for intents #5588

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions typescript/cli/src/config/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ import {

import { createAdvancedIsmConfig } from './ism.js';

const TYPE_DESCRIPTIONS: Record<TokenType, string> = {
const TYPE_DESCRIPTIONS: Record<
Exclude<TokenType, TokenType.intent | TokenType.intentNative>,
string
> = {
[TokenType.synthetic]: 'A new ERC20 with remote transfer functionality',
[TokenType.syntheticRebase]: `A rebasing ERC20 with remote transfer functionality. Must be paired with ${TokenType.collateralVaultRebase}`,
[TokenType.collateral]:
Expand All @@ -61,11 +64,18 @@ const TYPE_DESCRIPTIONS: Record<TokenType, string> = {
[TokenType.nativeScaled]: '',
};

const TYPE_CHOICES = Object.values(TokenType).map((type) => ({
name: type,
value: type,
description: TYPE_DESCRIPTIONS[type],
}));
const TYPE_CHOICES = Object.values(TokenType)
.filter(
(type) => type !== TokenType.intent && type !== TokenType.intentNative,
)
.map((type) => ({
name: type,
value: type,
description:
TYPE_DESCRIPTIONS[
type as Exclude<TokenType, TokenType.intent | TokenType.intentNative>
],
}));

async function fillDefaults(
context: CommandContext,
Expand Down Expand Up @@ -176,10 +186,10 @@ export async function createWarpRouteDeployConfig({
interchainSecurityModule = createDefaultWarpIsmConfig(owner);
}

const type = await select({
const type = (await select({
message: `Select ${chain}'s token type`,
choices: typeChoices,
});
})) as Exclude<TokenType, TokenType.intent | TokenType.intentNative>;

// TODO: restore NFT prompting
const isNft =
Expand Down
13 changes: 11 additions & 2 deletions typescript/cli/src/verify/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,22 @@ async function getWarpRouteFactory(
factory: ContractFactory;
tokenType: Exclude<
TokenType,
TokenType.syntheticUri | TokenType.collateralUri
| TokenType.syntheticUri
| TokenType.collateralUri
| TokenType.intent
| TokenType.intentNative
>;
}> {
const warpRouteReader = new EvmERC20WarpRouteReader(multiProvider, chainName);
const tokenType = (await warpRouteReader.deriveTokenType(
warpRouteAddress,
)) as Exclude<TokenType, TokenType.syntheticUri | TokenType.collateralUri>;
)) as Exclude<
TokenType,
| TokenType.syntheticUri
| TokenType.collateralUri
| TokenType.intent
| TokenType.intentNative
>;

const factory = objFilter(
hypERC20factories,
Expand Down
1 change: 1 addition & 0 deletions typescript/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"@arbitrum/sdk": "^4.0.0",
"@aws-sdk/client-s3": "^3.577.0",
"@bootnodedev/intents-framework-core": "^0.1.0",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need this to interact with the Hyperlane7683 contracts

"@chain-registry/types": "^0.50.14",
"@cosmjs/cosmwasm-stargate": "^0.32.4",
"@cosmjs/stargate": "^0.32.4",
Expand Down
8 changes: 4 additions & 4 deletions typescript/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export {
export { S3Config, S3Receipt, S3Wrapper } from './aws/s3.js';
export { S3Validator } from './aws/validator.js';
export {
TOKEN_EXCHANGE_RATE_DECIMALS_ETHEREUM,
TOKEN_EXCHANGE_RATE_SCALE_ETHEREUM,
getProtocolExchangeRateDecimals,
getProtocolExchangeRateScale,
TOKEN_EXCHANGE_RATE_DECIMALS_ETHEREUM,
TOKEN_EXCHANGE_RATE_SCALE_ETHEREUM,
} from './consts/igp.js';
export { MAILBOX_VERSION } from './consts/mailbox.js';
export {
Expand Down Expand Up @@ -129,10 +129,10 @@ export { HyperlaneIgp } from './gas/HyperlaneIgp.js';
export { HyperlaneIgpChecker } from './gas/HyperlaneIgpChecker.js';
export { HyperlaneIgpDeployer } from './gas/HyperlaneIgpDeployer.js';
export {
StorageGasOracleConfig,
StorageGasOracleConfigSchema,
ProtocolAgnositicGasOracleConfig,
ProtocolAgnositicGasOracleConfigSchema,
StorageGasOracleConfig,
StorageGasOracleConfigSchema,
} from './gas/oracle/types.js';
export { CoinGeckoTokenPriceGetter } from './gas/token-prices.js';
export {
Expand Down
1 change: 1 addition & 0 deletions typescript/sdk/src/token/IToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export interface IToken extends TokenArgs {
getHypAdapter(
multiProvider: MultiProtocolProvider<{ mailbox?: Address }>,
destination?: ChainName,
fillDeadline?: number,
): IHypTokenAdapter<unknown>;

getBalance(
Expand Down
2 changes: 2 additions & 0 deletions typescript/sdk/src/token/Token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ const STANDARD_TO_TOKEN: Record<TokenStandard, TokenArgs | null> = {
name: 'TIA.n',
},
[TokenStandard.CwHypSynthetic]: null,
[TokenStandard.EvmIntent]: null,
[TokenStandard.EvmIntentNative]: null,
};

const PROTOCOL_TO_ADDRESS_FOR_BALANCE_CHECK: Partial<
Expand Down
64 changes: 64 additions & 0 deletions typescript/sdk/src/token/Token.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import { MsgTransferEncodeObject } from '@cosmjs/stargate';
import { zeroAddress } from 'viem';

import {
Address,
Expand Down Expand Up @@ -45,6 +46,10 @@ import {
EvmHypSyntheticAdapter,
EvmHypXERC20Adapter,
EvmHypXERC20LockboxAdapter,
EvmIntentMultiChainAdapter,
EvmIntentNativeMultiChainAdapter,
EvmIntentNativeTokenAdapter,
EvmIntentTokenAdapter,
EvmNativeTokenAdapter,
EvmTokenAdapter,
} from './adapters/EvmTokenAdapter.js';
Expand Down Expand Up @@ -161,6 +166,22 @@ export class Token implements IToken {
sourceChannel: 'channel-0',
type: TokenConnectionType.Ibc,
});
} else if (standard === TokenStandard.EvmIntent) {
assert(
this.collateralAddressOrDenom,
'collateralAddressOrDenom required for EvmIntent tokens',
);
return new EvmIntentTokenAdapter(chainName, multiProvider, {
token: this.collateralAddressOrDenom,
router: addressOrDenom,
outputToken: zeroAddress,
});
} else if (standard === TokenStandard.EvmIntentNative) {
return new EvmIntentNativeTokenAdapter(chainName, multiProvider, {
token: this.collateralAddressOrDenom ?? zeroAddress,
router: addressOrDenom,
outputToken: zeroAddress,
});
} else {
throw new Error(`No adapter found for token standard: ${standard}`);
}
Expand All @@ -175,6 +196,7 @@ export class Token implements IToken {
getHypAdapter(
multiProvider: MultiProtocolProvider<{ mailbox?: Address }>,
destination?: ChainName,
fillDeadline: number = Math.floor(Date.now() / 1000) + 60 * 60 * 24,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fillDeadline is an intent-specific value that can only be accessed if it's passed via parameters at runtime.

It has a default value to 1 day (in seconds) if it's not defined in the request.

): IHypTokenAdapter<unknown> {
const { standard, chainName, addressOrDenom, collateralAddressOrDenom } =
this;
Expand Down Expand Up @@ -292,6 +314,44 @@ export class Token implements IToken {
const connection = this.getConnectionForChain(destination);
assert(connection, `No connection found for chain ${destination}`);
return this.getIbcAdapter(multiProvider, connection);
} else if (standard === TokenStandard.EvmIntent) {
assert(
this.collateralAddressOrDenom,
'collateralAddressOrDenom required for EvmIntent tokens',
);
Comment on lines +318 to +321
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressOrDenom hosts the address for the Hyperlane7683 instance (router), and collateralAddressOrDenom will be the ERC20 token address. That's why it's required when dealing with intents.

const outputToken =
destination &&
this.getConnectionForChain(destination)?.token.collateralAddressOrDenom;
assert(
outputToken,
`Couldn't find token on destination chain ${destination}`,
);
return new EvmIntentMultiChainAdapter(
chainName,
fillDeadline,
multiProvider,
{
router: addressOrDenom,
token: this.collateralAddressOrDenom,
outputToken,
},
);
} else if (standard === TokenStandard.EvmIntentNative) {
const outputToken =
(destination &&
this.getConnectionForChain(destination)?.token
.collateralAddressOrDenom) ||
zeroAddress; // when native, it can be undefined or null, thus default to zero address
return new EvmIntentNativeMultiChainAdapter(
chainName,
fillDeadline,
multiProvider,
{
router: addressOrDenom,
token: this.collateralAddressOrDenom ?? zeroAddress,
outputToken,
},
);
} else {
throw new Error(`No hyp adapter found for token standard: ${standard}`);
}
Expand Down Expand Up @@ -455,6 +515,10 @@ export class Token implements IToken {
return true;
}

if (this.standard === TokenStandard.EvmIntentNative) {
return true;
}

return false;
}
}
12 changes: 12 additions & 0 deletions typescript/sdk/src/token/TokenStandard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export enum TokenStandard {
EvmHypSyntheticRebase = 'EvmHypSyntheticRebase',
EvmHypXERC20 = 'EvmHypXERC20',
EvmHypXERC20Lockbox = 'EvmHypXERC20Lockbox',
EvmIntent = 'EvmIntent',
EvmIntentNative = 'EvmIntentNative',

// Sealevel (Solana)
SealevelSpl = 'SealevelSpl',
Expand Down Expand Up @@ -60,6 +62,8 @@ export const TOKEN_STANDARD_TO_PROTOCOL: Record<TokenStandard, ProtocolType> = {
EvmHypSyntheticRebase: ProtocolType.Ethereum,
EvmHypXERC20: ProtocolType.Ethereum,
EvmHypXERC20Lockbox: ProtocolType.Ethereum,
EvmIntent: ProtocolType.Ethereum,
EvmIntentNative: ProtocolType.Ethereum,
Comment on lines +65 to +66
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EmvIntent and EvmIntentNative are the standars that will identify the intents


// Sealevel (Solana)
SealevelSpl: ProtocolType.Sealevel,
Expand Down Expand Up @@ -133,8 +137,14 @@ export const TOKEN_HYP_STANDARDS = [
TokenStandard.CwHypSynthetic,
];

export const TOKEN_INTENT_STANDARDS = [
TokenStandard.EvmIntent,
TokenStandard.EvmIntentNative,
];

export const TOKEN_MULTI_CHAIN_STANDARDS = [
...TOKEN_HYP_STANDARDS,
...TOKEN_INTENT_STANDARDS,
TokenStandard.CosmosIbc,
];

Expand Down Expand Up @@ -164,6 +174,8 @@ export const TOKEN_TYPE_TO_STANDARD: Record<TokenType, TokenStandard> = {
[TokenType.syntheticUri]: TokenStandard.EvmHypSynthetic,
[TokenType.fastSynthetic]: TokenStandard.EvmHypSynthetic,
[TokenType.nativeScaled]: TokenStandard.EvmHypNative,
[TokenType.intent]: TokenStandard.EvmIntent,
[TokenType.intentNative]: TokenStandard.EvmIntentNative,
};

export const PROTOCOL_TO_NATIVE_STANDARD: Record<ProtocolType, TokenStandard> =
Expand Down
Loading