@@ -40,7 +40,7 @@ func (c ConfigureTokenPoolForRemoteChainInput) Validate(chain evm.Chain) error {
4040
4141var ConfigureTokenPoolForRemoteChain = cldf_ops .NewSequence (
4242 "configure-token-pool-for-remote-chain" ,
43- semver .MustParse ("1.7.0 " ),
43+ semver .MustParse ("1.6.1 " ),
4444 "Configures a token pool on an EVM chain for transfers with other chains" ,
4545 func (b cldf_ops.Bundle , chain evm.Chain , input ConfigureTokenPoolForRemoteChainInput ) (output sequences.OnChainOutput , err error ) {
4646 if err := input .Validate (chain ); err != nil {
@@ -57,6 +57,23 @@ var ConfigureTokenPoolForRemoteChain = cldf_ops.NewSequence(
5757 return sequences.OnChainOutput {}, fmt .Errorf ("failed to get supported chains: %w" , err )
5858 }
5959
60+ localDecimalsReport , err := cldf_ops .ExecuteOperation (b , token_pool .GetTokenDecimals , chain , evm_contract.FunctionInput [struct {}]{
61+ ChainSelector : input .ChainSelector ,
62+ Address : input .TokenPoolAddress ,
63+ })
64+ if err != nil {
65+ return sequences.OnChainOutput {}, fmt .Errorf ("failed to get token decimals: %w" , err )
66+ }
67+
68+ outboundConfig , inboundConfig := tokens .GenerateTPRLConfigs (
69+ input .RemoteChainConfig .DefaultFinalityOutboundRateLimiterConfig ,
70+ input .RemoteChainConfig .DefaultFinalityInboundRateLimiterConfig ,
71+ localDecimalsReport .Output ,
72+ input .RemoteChainConfig .RemoteDecimals ,
73+ chain .Family (),
74+ semver .MustParse ("1.6.1" ),
75+ )
76+
6077 // If the chain is supported
6178 // 1. Check remote token, remove and re-add remote config if requested remote token is different
6279 // 2. Check existing rate limiters and update if necessary
@@ -79,7 +96,7 @@ var ConfigureTokenPoolForRemoteChain = cldf_ops.NewSequence(
7996 // Only proceed further if we do NOT need to remove and re-add the chain
8097 if len (removes ) == 0 {
8198 // Check and update rate limiters
82- rateLimitersReport , err := maybeUpdateRateLimiters (b , chain , input )
99+ rateLimitersReport , err := maybeUpdateRateLimiters (b , chain , input . ChainSelector , input . TokenPoolAddress , input . RemoteChainSelector , inboundConfig , outboundConfig )
83100 if err != nil {
84101 return sequences.OnChainOutput {}, fmt .Errorf ("failed to maybe update rate limiters: %w" , err )
85102 }
@@ -139,14 +156,14 @@ var ConfigureTokenPoolForRemoteChain = cldf_ops.NewSequence(
139156 },
140157 RemoteTokenAddress : common .LeftPadBytes (input .RemoteChainConfig .RemoteToken , 32 ),
141158 OutboundRateLimiterConfig : token_pool.Config {
142- IsEnabled : input . RemoteChainConfig . DefaultFinalityOutboundRateLimiterConfig .IsEnabled ,
143- Capacity : input . RemoteChainConfig . DefaultFinalityOutboundRateLimiterConfig .Capacity ,
144- Rate : input . RemoteChainConfig . DefaultFinalityOutboundRateLimiterConfig .Rate ,
159+ IsEnabled : outboundConfig .IsEnabled ,
160+ Capacity : outboundConfig .Capacity ,
161+ Rate : outboundConfig .Rate ,
145162 },
146163 InboundRateLimiterConfig : token_pool.Config {
147- IsEnabled : input . RemoteChainConfig . DefaultFinalityInboundRateLimiterConfig .IsEnabled ,
148- Capacity : input . RemoteChainConfig . DefaultFinalityInboundRateLimiterConfig .Capacity ,
149- Rate : input . RemoteChainConfig . DefaultFinalityInboundRateLimiterConfig .Rate ,
164+ IsEnabled : inboundConfig .IsEnabled ,
165+ Capacity : inboundConfig .Capacity ,
166+ Rate : inboundConfig .Rate ,
150167 },
151168 },
152169 },
@@ -167,44 +184,52 @@ var ConfigureTokenPoolForRemoteChain = cldf_ops.NewSequence(
167184)
168185
169186// maybeUpdateRateLimiters checks and updates the rate limiters for a given remote chain if they do not match the desired config.
170- func maybeUpdateRateLimiters (b cldf_ops.Bundle , chain evm.Chain , input ConfigureTokenPoolForRemoteChainInput ) (output evm_contract.WriteOutput , err error ) {
187+ func maybeUpdateRateLimiters (
188+ b cldf_ops.Bundle ,
189+ chain evm.Chain ,
190+ chainSelector uint64 ,
191+ tokenPoolAddress common.Address ,
192+ remoteChainSelector uint64 ,
193+ inboundConfig tokens.RateLimiterConfig ,
194+ outboundConfig tokens.RateLimiterConfig ,
195+ ) (output evm_contract.WriteOutput , err error ) {
171196 inboundRateLimiterStateReport , err := cldf_ops .ExecuteOperation (b , token_pool .GetCurrentInboundRateLimiterState , chain , evm_contract.FunctionInput [uint64 ]{
172- ChainSelector : input . ChainSelector ,
173- Address : input . TokenPoolAddress ,
174- Args : input . RemoteChainSelector ,
197+ ChainSelector : chainSelector ,
198+ Address : tokenPoolAddress ,
199+ Args : remoteChainSelector ,
175200 })
176201 if err != nil {
177202 return evm_contract.WriteOutput {}, fmt .Errorf ("failed to get inbound rate limiter state: %w" , err )
178203 }
179204 currentInboundRateLimiterState := inboundRateLimiterStateReport .Output
180205
181206 outboundRateLimiterStateReport , err := cldf_ops .ExecuteOperation (b , token_pool .GetCurrentOutboundRateLimiterState , chain , evm_contract.FunctionInput [uint64 ]{
182- ChainSelector : input . ChainSelector ,
183- Address : input . TokenPoolAddress ,
184- Args : input . RemoteChainSelector ,
207+ ChainSelector : chainSelector ,
208+ Address : tokenPoolAddress ,
209+ Args : remoteChainSelector ,
185210 })
186211 if err != nil {
187212 return evm_contract.WriteOutput {}, fmt .Errorf ("failed to get outbound rate limiter state: %w" , err )
188213 }
189214 currentOutboundRateLimiterState := outboundRateLimiterStateReport .Output
190215
191216 // Update the rate limiters if they do not match the desired config
192- if ! rateLimiterConfigsEqual (currentInboundRateLimiterState , input . RemoteChainConfig . DefaultFinalityInboundRateLimiterConfig ) ||
193- ! rateLimiterConfigsEqual (currentOutboundRateLimiterState , input . RemoteChainConfig . DefaultFinalityOutboundRateLimiterConfig ) {
217+ if ! rateLimiterConfigsEqual (currentInboundRateLimiterState , inboundConfig ) ||
218+ ! rateLimiterConfigsEqual (currentOutboundRateLimiterState , outboundConfig ) {
194219 setInboundRateLimiterReport , err := cldf_ops .ExecuteOperation (b , token_pool .SetChainRateLimiterConfig , chain , evm_contract.FunctionInput [token_pool.SetChainRateLimiterConfigArgs ]{
195- ChainSelector : input . ChainSelector ,
196- Address : input . TokenPoolAddress ,
220+ ChainSelector : chainSelector ,
221+ Address : tokenPoolAddress ,
197222 Args : token_pool.SetChainRateLimiterConfigArgs {
198- RemoteChainSelector : input . RemoteChainSelector ,
223+ RemoteChainSelector : remoteChainSelector ,
199224 InboundConfig : token_pool.Config {
200- IsEnabled : input . RemoteChainConfig . DefaultFinalityInboundRateLimiterConfig .IsEnabled ,
201- Capacity : input . RemoteChainConfig . DefaultFinalityInboundRateLimiterConfig .Capacity ,
202- Rate : input . RemoteChainConfig . DefaultFinalityInboundRateLimiterConfig .Rate ,
225+ IsEnabled : inboundConfig .IsEnabled ,
226+ Capacity : inboundConfig .Capacity ,
227+ Rate : inboundConfig .Rate ,
203228 },
204229 OutboundConfig : token_pool.Config {
205- IsEnabled : input . RemoteChainConfig . DefaultFinalityOutboundRateLimiterConfig .IsEnabled ,
206- Capacity : input . RemoteChainConfig . DefaultFinalityOutboundRateLimiterConfig .Capacity ,
207- Rate : input . RemoteChainConfig . DefaultFinalityOutboundRateLimiterConfig .Rate ,
230+ IsEnabled : outboundConfig .IsEnabled ,
231+ Capacity : outboundConfig .Capacity ,
232+ Rate : outboundConfig .Rate ,
208233 },
209234 },
210235 })
0 commit comments