@@ -3,9 +3,11 @@ package util
33import (
44 "context"
55 "math/big"
6+ "strings"
67
78 "github.com/0xPolygon/polygon-cli/bindings/multicall3"
89 "github.com/0xPolygon/polygon-cli/bindings/tokens"
10+ "github.com/ethereum/go-ethereum/accounts/abi"
911 "github.com/ethereum/go-ethereum/accounts/abi/bind/v2"
1012 "github.com/ethereum/go-ethereum/common"
1113 "github.com/ethereum/go-ethereum/core/types"
@@ -145,16 +147,20 @@ func Multicall3FundAccountsWithERC20Token(ctx context.Context, c *ethclient.Clie
145147 return nil , nil , err
146148 }
147149
148- erc20 , err := tokens .NewERC20 (tokenAddress , c )
150+ // Calculate total amount needed
151+ totalAmount := big .NewInt (0 ).Mul (amount , big .NewInt (int64 (len (accounts ))))
152+
153+ // Create ABI for mint(address, uint256) function to mint tokens to multicall3
154+ mintABI , err := abi .JSON (strings .NewReader (`[{"type":"function","name":"mint","inputs":[{"name":"to","type":"address"},{"name":"amount","type":"uint256"}],"outputs":[],"stateMutability":"nonpayable"}]` ))
149155 if err != nil {
150156 return nil , nil , err
151157 }
152158
153- // Calculate total amount to approve
154- totalAmount := big . NewInt ( 0 ). Mul ( amount , big . NewInt ( int64 ( len ( accounts ))) )
159+ // Create bound contract for minting
160+ mintContract := bind . NewBoundContract ( tokenAddress , mintABI , c , c , c )
155161
156- // Prepare approve calldata for the Multicall3 contract to spend tokens
157- approveTx , err = erc20 . Approve (tops , scAddr , totalAmount )
162+ // Mint tokens directly to multicall3 contract so it can distribute them
163+ approveTx , err = mintContract . Transact (tops , "mint" , scAddr , totalAmount )
158164 if err != nil {
159165 return nil , nil , err
160166 }
@@ -169,9 +175,11 @@ func Multicall3FundAccountsWithERC20Token(ctx context.Context, c *ethclient.Clie
169175 return approveTx , nil , err
170176 }
171177
178+ // Now prepare multicall3 calls to transfer tokens from multicall3 to each account
179+ // Using transfer instead of transferFrom since multicall3 now owns the tokens
172180 calls := make ([]multicall3.Multicall3Call3 , 0 , len (accounts ))
173181 for _ , account := range accounts {
174- callData , iErr := erc20ABI .Pack ("transferFrom" , tops . From , account , amount )
182+ callData , iErr := erc20ABI .Pack ("transfer" , account , amount )
175183 if iErr != nil {
176184 return approveTx , nil , iErr
177185 }
0 commit comments