@@ -14,7 +14,14 @@ import dayjs from 'dayjs';
1414import { BigNumber , BigNumberish , constants } from 'ethers' ;
1515import { produce } from 'immer' ;
1616import { Approval } from 'src/helpers/useTransactionHandler' ;
17+ import { CustomMarket } from 'src/ui-config/marketsConfig' ;
18+ import { marketsData } from 'src/utils/marketsAndNetworksConfig' ;
1719import { StateCreator } from 'zustand' ;
20+ import {
21+ selectCurrentChainIdV2MarketData ,
22+ selectCurrentChainIdV2MarketKey ,
23+ selectCurrentChainIdV3MarketKey ,
24+ } from './poolSelectors' ;
1825
1926import { RootStore } from './root' ;
2027import {
@@ -51,8 +58,7 @@ export type V3MigrationSlice = {
5158 migrateBorrow : (
5259 signedPermits ?: V3MigrationHelperSignedPermit [ ]
5360 ) => Promise < EthereumTransactionTypeExtended [ ] > ;
54- _testMigration : ( ) => void ;
55- // migrateSelectedPositions: () => void;
61+ setCurrentMarketForMigration : ( ) => void ;
5662} ;
5763
5864export const createV3MigrationSlice : StateCreator <
@@ -142,13 +148,11 @@ export const createV3MigrationSlice: StateCreator<
142148 const timestamp = dayjs ( ) . unix ( ) ;
143149 const approvalPermitsForMigrationAssets = await Promise . all (
144150 selectUserSupplyIncreasedReservesForMigrationPermits ( get ( ) , timestamp ) . map (
145- async ( { reserve, increasedAmount, underlyingBalance } ) : Promise < Approval > => {
146- console . log ( underlyingBalance , 'underlyingBalance' ) ;
151+ async ( { reserve, increasedAmount } ) : Promise < Approval > => {
147152 const { getTokenData } = new ERC20Service ( get ( ) . jsonRpcProvider ( ) ) ;
148153 const { decimals } = await getTokenData ( reserve . aTokenAddress ) ;
149154 const convertedAmount = valueToWei ( increasedAmount , decimals ) ;
150155 return {
151- // TODO: should we allow spending of exact ammount of the reserver?
152156 amount : convertedAmount ,
153157 underlyingAsset : reserve . aTokenAddress ,
154158 permitType : 'MIGRATOR' ,
@@ -160,7 +164,6 @@ export const createV3MigrationSlice: StateCreator<
160164 return approvalPermitsForMigrationAssets ;
161165 } ,
162166 migrateWithoutPermits : ( ) => {
163- console . log ( 'should be called before gas' ) ;
164167 const timestamp = dayjs ( ) . unix ( ) ;
165168 set ( { timestamp } ) ;
166169 const borrowedPositions = selectUserBorrowReservesForMigration ( get ( ) , timestamp ) ;
@@ -206,28 +209,21 @@ export const createV3MigrationSlice: StateCreator<
206209 }
207210 const provider = get ( ) . jsonRpcProvider ( ) ;
208211 const migratorAddress = get ( ) . getMigratorAddress ( ) ;
209- const currentMarketData = get ( ) . currentMarketData ;
212+
210213 // TODO: make it dynamic when network switch will be there
214+ const v3MarketKey = selectCurrentChainIdV3MarketKey ( get ( ) ) ;
215+ const currentMarketV3Data = marketsData [ v3MarketKey ] ;
211216 const pool = new Pool ( provider , {
212- POOL : '0x794a61358D6845594F94dc1DB02A252b5b4814aD' ,
213- REPAY_WITH_COLLATERAL_ADAPTER : currentMarketData . addresses . REPAY_WITH_COLLATERAL_ADAPTER ,
214- SWAP_COLLATERAL_ADAPTER : currentMarketData . addresses . SWAP_COLLATERAL_ADAPTER ,
215- WETH_GATEWAY : currentMarketData . addresses . WETH_GATEWAY ,
216- L2_ENCODER : currentMarketData . addresses . L2_ENCODER ,
217+ POOL : currentMarketV3Data . addresses . LENDING_POOL ,
218+ REPAY_WITH_COLLATERAL_ADAPTER : currentMarketV3Data . addresses . REPAY_WITH_COLLATERAL_ADAPTER ,
219+ SWAP_COLLATERAL_ADAPTER : currentMarketV3Data . addresses . SWAP_COLLATERAL_ADAPTER ,
220+ WETH_GATEWAY : currentMarketV3Data . addresses . WETH_GATEWAY ,
221+ L2_ENCODER : currentMarketV3Data . addresses . L2_ENCODER ,
217222 } ) ;
218223 const newMigratorInstance = new V3MigrationHelperService ( provider , migratorAddress , pool ) ;
219224 // TODO: don't forget to add maping here
220225 return newMigratorInstance ;
221226 } ,
222- _testMigration : async ( ) => {
223- const currentTimestamp = dayjs ( ) . unix ( ) ;
224- const selectedReservers = selectedUserSupplyReservesForMigration ( get ( ) , currentTimestamp ) ;
225- const mappedAddresses = await Promise . all (
226- selectedReservers . map ( ( reserve ) =>
227- get ( ) . getMigrationServiceInstance ( ) . testDeployment ( reserve . underlyingAsset )
228- )
229- ) ;
230- } ,
231227 migrateBorrow : async ( signedPermits : V3MigrationHelperSignedPermit [ ] = [ ] ) => {
232228 const currentTimestamp = dayjs ( ) . unix ( ) ;
233229 const user = get ( ) . account ;
@@ -249,5 +245,10 @@ export const createV3MigrationSlice: StateCreator<
249245 signedPermits,
250246 } ) ;
251247 } ,
248+ setCurrentMarketForMigration : ( ) => {
249+ const newMarketData = selectCurrentChainIdV2MarketKey ( get ( ) ) ;
250+ // TOOD: fallback to mainnet if newMarketData do not support v2 and v3
251+ get ( ) . setCurrentMarket ( newMarketData ) ;
252+ } ,
252253 } ;
253254} ;
0 commit comments