Skip to content

Commit

Permalink
test: dynamically fetch dest gas amt
Browse files Browse the repository at this point in the history
  • Loading branch information
DhairyaSethi committed Oct 30, 2024
1 parent 9abb6d3 commit ced148d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/20241021_Multi_GHOCCIP150Upgrade/utils/CCIPUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ library CCIPUtils {
),
destTokenAddress: abi.encode(params.destinationToken),
extraData: '',
destGasAmount: 90000
destGasAmount: getDestGasAmount(onRamp, params.message.tokenAmounts[i].token)
})
);
}
Expand Down Expand Up @@ -150,4 +150,12 @@ library CCIPUtils {
)
);
}

function getDestGasAmount(IEVM2EVMOnRamp onRamp, address token) internal view returns (uint32) {
IEVM2EVMOnRamp.TokenTransferFeeConfig memory config = onRamp.getTokenTransferFeeConfig(token);
return
config.isEnabled
? config.destGasOverhead
: onRamp.getDynamicConfig().defaultTokenDestGasOverhead;
}
}
38 changes: 38 additions & 0 deletions src/interfaces/ccip/IEVM2EVMOnRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@ pragma solidity ^0.8.0;
import {IInternal} from './IInternal.sol';

interface IEVM2EVMOnRamp {
struct TokenTransferFeeConfig {
uint32 minFeeUSDCents; // ──────────╮ Minimum fee to charge per token transfer, multiples of 0.01 USD
uint32 maxFeeUSDCents; // │ Maximum fee to charge per token transfer, multiples of 0.01 USD
uint16 deciBps; // │ Basis points charged on token transfers, multiples of 0.1bps, or 1e-5
uint32 destGasOverhead; // │ Gas charged to execute the token transfer on the destination chain
// │ Extra data availability bytes that are returned from the source pool and sent
uint32 destBytesOverhead; // │ to the destination pool. Must be >= Pool.CCIP_LOCK_OR_BURN_V1_RET_BYTES
bool aggregateRateLimitEnabled; // │ Whether this transfer token is to be included in Aggregate Rate Limiting
bool isEnabled; // ─────────────────╯ Whether this token has custom transfer fees
}

struct DynamicConfig {
address router; // ──────────────────────────╮ Router address
uint16 maxNumberOfTokensPerMsg; // │ Maximum number of distinct ERC20 token transferred per message
uint32 destGasOverhead; // │ Gas charged on top of the gasLimit to cover destination chain costs
uint16 destGasPerPayloadByte; // │ Destination chain gas charged for passing each byte of `data` payload to receiver
uint32 destDataAvailabilityOverheadGas; // ──╯ Extra data availability gas charged on top of the message, e.g. for OCR
uint16 destGasPerDataAvailabilityByte; // ───╮ Amount of gas to charge per byte of message data that needs availability
uint16 destDataAvailabilityMultiplierBps; // │ Multiplier for data availability gas, multiples of bps, or 0.0001
address priceRegistry; // │ Price registry address
uint32 maxDataBytes; // │ Maximum payload data size in bytes
uint32 maxPerMsgGasLimit; // ────────────────╯ Maximum gas limit for messages targeting EVMs
// │
// The following three properties are defaults, they can be overridden by setting the TokenTransferFeeConfig for a token
uint16 defaultTokenFeeUSDCents; // ──────────╮ Default token fee charged per token transfer
uint32 defaultTokenDestGasOverhead; // │ Default gas charged to execute the token transfer on the destination chain
bool enforceOutOfOrder; // ──────────────────╯ Whether to enforce the allowOutOfOrderExecution extraArg value to be true.
}

/// @notice Gets the next sequence number to be used in the onRamp
/// @return the next sequence number to be used
function getExpectedNextSequenceNumber() external view returns (uint64);
Expand All @@ -30,4 +59,13 @@ interface IEVM2EVMOnRamp {
uint64 destChainSelector,
address sourceToken
) external view returns (address);

/// @notice Gets the transfer fee config for a given token.
function getTokenTransferFeeConfig(
address token
) external view returns (TokenTransferFeeConfig memory tokenTransferFeeConfig);

/// @notice Returns the dynamic onRamp config.
/// @return dynamicConfig the configuration.
function getDynamicConfig() external view returns (DynamicConfig memory dynamicConfig);
}

0 comments on commit ced148d

Please sign in to comment.