11//SPDX-License-Identifier:MIT
2- pragma solidity ^ 0.8.24 ;
2+ pragma solidity ^ 0.8.24 ;
33
44import {TokenPool} from "@ccip/contracts/src/v0.8/ccip/pools/TokenPool.sol " ;
55import {IERC20 } from "@ccip/contracts/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol " ;
66import {IRebaseToken} from "./interfaces/IRebaseToken.sol " ; // Adjust path if your interface is elsewhere
77import {Pool} from "@ccip/contracts/src/v0.8/ccip/libraries/Pool.sol " ; // For CCIP structs
88
9- contract RebaseTokenPool is TokenPool {
10-
11- /*** The TokenPool base constructor requires:
12- * @_token: The address of the rebase token this pool will manage.
13- * @
14- * @localTokenDecimals: The decimals of the token. Here, it's hardcoded to 18.
15- * @
16- * @_allowlist: An array of addresses permitted to send tokens through this pool.
17- * @
18- * @_rnmProxy: The address of the CCIP Risk Management Network (RMN) proxy.
19- * @
20- * @_router: The address of the CCIP router contract.
21- */
22- constructor (
23- IERC20 _token ,
24- address [] memory _allowList ,
25- address i_rmnProxy ,
26- address _router
27- )TokenPool (_token,_allowList,i_rmnProxy,_router){
28- //constructor body
29- }
30-
9+ contract RebaseTokenPool is TokenPool {
10+ /**
11+ * The TokenPool base constructor requires:
12+ * @_token: The address of the rebase token this pool will manage.
13+ * @
14+ * @localTokenDecimals: The decimals of the token. Here, it's hardcoded to 18.
15+ * @
16+ * @_allowlist: An array of addresses permitted to send tokens through this pool.
17+ * @
18+ * @_rnmProxy: The address of the CCIP Risk Management Network (RMN) proxy.
19+ * @
20+ * @_router: The address of the CCIP router contract.
21+ */
22+ constructor (IERC20 _token , address [] memory _allowList , address i_rmnProxy , address _router )
23+ TokenPool (_token, _allowList, i_rmnProxy, _router)
24+ {
25+ //constructor body
26+ }
3127
32- // lockorburn function to process burning upon transfering
33- function lockOrBurn (Pool.LockOrBurnInV1 calldata lockOrBurnIn ) external returns (Pool.LockOrBurnOutV1 memory lockOrBurnOut ) {
28+ // lockorburn function to process burning upon transfering
29+ function lockOrBurn (Pool.LockOrBurnInV1 calldata lockOrBurnIn )
30+ external
31+ override
32+ returns (Pool.LockOrBurnOutV1 memory lockOrBurnOut )
33+ {
3434 _validateLockOrBurn (lockOrBurnIn);
35- // Decode the original sender's address
36- address originalSender = abi.decode (lockOrBurnIn.originalSender, (address ));
37-
38- // Fetch the user's current interest rate from the rebase token
39- uint256 userInterestRate = IRebaseToken (address (i_token)).getUserInterestRate (originalSender);
40- // Burn the specified amount of tokens from this pool contract
41- // CCIP transfers tokens to the pool before lockOrBurn is called
35+ // Burn the tokens on the source chain. This returns their userAccumulatedInterest before the tokens were burned (in case all tokens were burned, we don't want to send 0 cross-chain)
36+ uint256 userInterestRate = IRebaseToken (address (i_token)).getUserInterestRate (lockOrBurnIn.originalSender);
4237 IRebaseToken (address (i_token)).burn (address (this ), lockOrBurnIn.amount);
43- // Prepare the output data for CCIP
38+ // encode a function call to pass the caller's info to the destination pool and update it
4439 lockOrBurnOut = Pool.LockOrBurnOutV1 ({
4540 destTokenAddress: getRemoteToken (lockOrBurnIn.remoteChainSelector),
46- destPoolData: abi.encode (userInterestRate) // Encode the interest rate to send cross-chain
41+ destPoolData: abi.encode (userInterestRate)
4742 });
48- // No explicit return statement is needed due to the named return variable
43+ // because of named return variable in the function signature : no explicit return statement is needed
4944 }
5045
5146 // when tokens are beign receive on the chain where this RebaseTokenPool is deployed
52- function releaseOrMint (
53- Pool.ReleaseOrMintInV1 calldata releaseOrMintIn
54- ) external override returns (Pool.ReleaseOrMintOutV1 memory /* releaseOrMintOut */ ) { // Named return optional
47+ function releaseOrMint (Pool.ReleaseOrMintInV1 calldata releaseOrMintIn )
48+ external
49+ override
50+ returns (Pool.ReleaseOrMintOutV1 memory /* releaseOrMintOut */ )
51+ {
52+ // Named return optional
5553 _validateReleaseOrMint (releaseOrMintIn);
5654 // Decode the user interest rate sent from the source pool
5755 uint256 userInterestRate = abi.decode (releaseOrMintIn.sourcePoolData, (uint256 ));
58-
5956 // The receiver address is directly available
6057 address receiver = releaseOrMintIn.receiver;
6158 // Mint tokens to the receiver, applying the propagated interest rate
@@ -64,9 +61,6 @@ contract RebaseTokenPool is TokenPool{
6461 releaseOrMintIn.amount,
6562 userInterestRate // Pass the interest rate to the rebase token's mint function
6663 );
67- return Pool.ReleaseOrMintOutV1 ({
68- destinationAmount: releaseOrMintIn.amount
69- });
64+ return Pool.ReleaseOrMintOutV1 ({destinationAmount: releaseOrMintIn.amount});
7065 }
71-
72- }
66+ }
0 commit comments