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

Add max mint limit constraint #5492

Open
wants to merge 2 commits into
base: ccip-warp-route
Choose a base branch
from
Open
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
9 changes: 2 additions & 7 deletions typescript/sdk/src/token/EvmERC20WarpRouteReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,9 @@ export class EvmERC20WarpRouteReader extends HyperlaneReader {
}

async fetchXERC20Config(
type: TokenType.XERC20 | TokenType.XERC20Lockbox,
xERC20Address: Address,
warpRouteAddress: Address,
): Promise<XERC20TokenMetadata | {}> {
): Promise<XERC20TokenMetadata> {
// fetch the limits if possible
const rateLimitsABI = [
'function rateLimitPerSecond(address) external view returns (uint128)',
Expand Down Expand Up @@ -272,11 +271,7 @@ export class EvmERC20WarpRouteReader extends HyperlaneReader {
await this.fetchERC20Metadata(token);

if (type === TokenType.XERC20 || type === TokenType.XERC20Lockbox) {
xERC20Metadata = await this.fetchXERC20Config(
type,
token,
warpRouteAddress,
);
xERC20Metadata = await this.fetchXERC20Config(token, warpRouteAddress);
}

return {
Expand Down
16 changes: 16 additions & 0 deletions typescript/sdk/src/token/Token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ const STANDARD_TO_TOKEN: Record<TokenStandard, TokenArgs | null> = {
symbol: 'USDC',
name: 'USDC',
},
[TokenStandard.EvmHypVSXERC20]: {
chainName: TestChainName.test2,
standard: TokenStandard.EvmHypVSXERC20,
addressOrDenom: '0x8358D8291e3bEDb04804975eEa0fe9fe0fAfB147',
decimals: 6,
symbol: 'USDC',
name: 'USDC',
},
[TokenStandard.EvmHypVSXERC20Lockbox]: {
chainName: TestChainName.test2,
standard: TokenStandard.EvmHypVSXERC20Lockbox,
addressOrDenom: '0x8358D8291e3bEDb04804975eEa0fe9fe0fAfB147',
decimals: 6,
symbol: 'USDC',
name: 'USDC',
},

// Sealevel
[TokenStandard.SealevelSpl]: {
Expand Down
8 changes: 8 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',
EvmHypVSXERC20 = 'EvmHypVSXERC20',
EvmHypVSXERC20Lockbox = 'EvmHypVSXERC20Lockbox',

// 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,
EvmHypVSXERC20: ProtocolType.Ethereum,
EvmHypVSXERC20Lockbox: ProtocolType.Ethereum,

// Sealevel (Solana)
SealevelSpl: ProtocolType.Sealevel,
Expand Down Expand Up @@ -111,6 +115,8 @@ export const TOKEN_COLLATERALIZED_STANDARDS = [
export const XERC20_STANDARDS = [
TokenStandard.EvmHypXERC20,
TokenStandard.EvmHypXERC20Lockbox,
TokenStandard.EvmHypVSXERC20,
TokenStandard.EvmHypVSXERC20Lockbox,
];

export const MINT_LIMITED_STANDARDS = [...XERC20_STANDARDS];
Expand All @@ -125,6 +131,8 @@ export const TOKEN_HYP_STANDARDS = [
TokenStandard.EvmHypSyntheticRebase,
TokenStandard.EvmHypXERC20,
TokenStandard.EvmHypXERC20Lockbox,
TokenStandard.EvmHypVSXERC20,
TokenStandard.EvmHypVSXERC20Lockbox,
TokenStandard.SealevelHypNative,
TokenStandard.SealevelHypCollateral,
TokenStandard.SealevelHypSynthetic,
Expand Down
25 changes: 21 additions & 4 deletions typescript/sdk/src/warp/WarpCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,28 @@ export class WarpCore {
const adapter = destinationToken.getAdapter(this.multiProvider);
if (
destinationToken.standard === TokenStandard.EvmHypXERC20 ||
destinationToken.standard === TokenStandard.EvmHypXERC20Lockbox
destinationToken.standard === TokenStandard.EvmHypXERC20Lockbox ||
destinationToken.standard === TokenStandard.EvmHypVSXERC20 ||
destinationToken.standard === TokenStandard.EvmHypVSXERC20Lockbox
) {
destinationBalance = await (
adapter as IHypXERC20Adapter<unknown>
).getMintLimit();
const adapter = destinationToken.getAdapter(
this.multiProvider,
) as IHypXERC20Adapter<unknown>;
destinationBalance = await adapter.getMintLimit();

if (
destinationToken.standard === TokenStandard.EvmHypVSXERC20 ||
Copy link
Contributor

Choose a reason for hiding this comment

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

How will this standard get set? Right now, it is not yeah? wouldn't we need a corresponding change in the warp core config artifact?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, the config artifact is only in the UI afaik?

Copy link
Member Author

Choose a reason for hiding this comment

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

this doesnt need to be urgently merged as @Xaroz already made the change on the UI
this just protects against onchain limit changes

destinationToken.standard === TokenStandard.EvmHypVSXERC20Lockbox
) {
const bufferCap = await adapter.getMintMaxLimit();
const max = bufferCap / 2n;
Copy link
Contributor

@Mo-Hussain Mo-Hussain Feb 17, 2025

Choose a reason for hiding this comment

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

If the limit has not replenished to the midpoint and is above it i.e we have recently burned more than minted, we would be allowed to mint more than half the buffer cap at this point.

We could instead check if destinationBalance is greater than getMintLimit()

Copy link
Member Author

Choose a reason for hiding this comment

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

@nambrot wants to avoid this situation where the mint limit is decreasing and the latency of message delivery can cause the transfer to appear mintable at dispatch time but not at process time

Copy link
Member Author

Choose a reason for hiding this comment

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

otherwise we would not have made any changes to this adapter

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense

if (destinationBalance > max) {
this.logger.debug(
`Mint limit ${destinationBalance} exceeds max ${max}, using max`,
);
destinationBalance = max;
}
}
} else {
destinationBalance = await adapter.getBalance(
destinationToken.addressOrDenom,
Expand Down
Loading