-
Notifications
You must be signed in to change notification settings - Fork 444
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, | ||
|
@@ -45,6 +46,10 @@ import { | |
EvmHypSyntheticAdapter, | ||
EvmHypXERC20Adapter, | ||
EvmHypXERC20LockboxAdapter, | ||
EvmIntentMultiChainAdapter, | ||
EvmIntentNativeMultiChainAdapter, | ||
EvmIntentNativeTokenAdapter, | ||
EvmIntentTokenAdapter, | ||
EvmNativeTokenAdapter, | ||
EvmTokenAdapter, | ||
} from './adapters/EvmTokenAdapter.js'; | ||
|
@@ -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}`); | ||
} | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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; | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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}`); | ||
} | ||
|
@@ -455,6 +515,10 @@ export class Token implements IToken { | |
return true; | ||
} | ||
|
||
if (this.standard === TokenStandard.EvmIntentNative) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ export enum TokenStandard { | |
EvmHypSyntheticRebase = 'EvmHypSyntheticRebase', | ||
EvmHypXERC20 = 'EvmHypXERC20', | ||
EvmHypXERC20Lockbox = 'EvmHypXERC20Lockbox', | ||
EvmIntent = 'EvmIntent', | ||
EvmIntentNative = 'EvmIntentNative', | ||
|
||
// Sealevel (Solana) | ||
SealevelSpl = 'SealevelSpl', | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// Sealevel (Solana) | ||
SealevelSpl: ProtocolType.Sealevel, | ||
|
@@ -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, | ||
]; | ||
|
||
|
@@ -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> = | ||
|
There was a problem hiding this comment.
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