@@ -25,65 +25,64 @@ type PositionsCreateWithEthForPolygon = (options: {
2525 readonly create : ( ) => Promise < UndefinedOr < ApproveIfNeededResult > >
2626} >
2727
28- export const positionsCreateWithEth : PositionsCreateWithEthForPolygon = async (
29- options ,
30- ) => {
31- const [ , l2 , weth ] = await clientsUtilsSwapForStake ( options . provider )
28+ export const positionsCreateWithEthForPolygon : PositionsCreateWithEthForPolygon =
29+ async ( options ) => {
30+ const [ , l2 , weth ] = await clientsUtilsSwapForStake ( options . provider )
3231
33- return l2 && weth
34- ? {
35- estimatedDev : options . ethAmount
36- ? await l2 . getEstimatedDevForEth ( options . ethAmount )
37- : 'No ethAmount provided' ,
38- estimatedEth : options . devAmount
39- ? await l2 . getEstimatedEthForDev ( options . devAmount )
40- : 'No devAmount provided' ,
41- create : async ( ) =>
42- whenDefined ( options . from , async ( from ) => {
43- const ethAmount = options . ethAmount
44- ? options . ethAmount
45- : options . devAmount
46- ? await l2 . getEstimatedEthForDev ( options . devAmount )
47- : 'Neither ethAmount nor devAmount provided'
48- const _overrides = {
49- overrides : {
50- ...options . overrides ?. overrides ,
51- } ,
52- }
32+ return l2 && weth
33+ ? {
34+ estimatedDev : options . ethAmount
35+ ? await l2 . getEstimatedDevForEth ( options . ethAmount )
36+ : 'No ethAmount provided' ,
37+ estimatedEth : options . devAmount
38+ ? await l2 . getEstimatedEthForDev ( options . devAmount )
39+ : 'No devAmount provided' ,
40+ create : async ( ) =>
41+ whenDefined ( options . from , async ( from ) => {
42+ const ethAmount = options . ethAmount
43+ ? options . ethAmount
44+ : options . devAmount
45+ ? await l2 . getEstimatedEthForDev ( options . devAmount )
46+ : 'Neither ethAmount nor devAmount provided'
47+ const _overrides = {
48+ overrides : {
49+ ...options . overrides ?. overrides ,
50+ } ,
51+ }
5352
54- return approveIfNeeded ( {
55- provider : options . provider ,
56- requiredAmount : ethAmount ,
57- from,
58- token : weth ,
59- to : await l2 . contract ( ) . getAddress ( ) ,
60- callback : async ( ) => {
61- const deadline = options . deadline
62- ? options . deadline
63- : ( ( await options . provider . provider ?. getBlock ( 'latest' ) )
64- ?. timestamp ?? Math . floor ( new Date ( ) . getTime ( ) / 1000 ) ) +
65- 300
66- return options . gatewayAddress &&
67- typeof options . gatewayBasisPoints === 'number'
68- ? l2 . swapEthAndStakeDevPolygonCaller (
69- options . destination ,
70- ethAmount ,
71- deadline ,
72- options . payload ?? ZeroHash ,
73- _overrides ,
74- options . gatewayAddress ,
75- String ( options . gatewayBasisPoints ) ,
76- )
77- : l2 . swapEthAndStakeDevPolygonCaller (
78- options . destination ,
79- ethAmount ,
80- deadline ,
81- options . payload ?? ZeroHash ,
82- _overrides ,
83- )
84- } ,
85- } )
86- } ) ,
87- }
88- : ( undefined as never )
89- }
53+ return approveIfNeeded ( {
54+ provider : options . provider ,
55+ requiredAmount : ethAmount ,
56+ from,
57+ token : weth ,
58+ to : await l2 . contract ( ) . getAddress ( ) ,
59+ callback : async ( ) => {
60+ const deadline = options . deadline
61+ ? options . deadline
62+ : ( ( await options . provider . provider ?. getBlock ( 'latest' ) )
63+ ?. timestamp ??
64+ Math . floor ( new Date ( ) . getTime ( ) / 1000 ) ) + 300
65+ return options . gatewayAddress &&
66+ typeof options . gatewayBasisPoints === 'number'
67+ ? l2 . swapEthAndStakeDevPolygonCaller (
68+ options . destination ,
69+ ethAmount ,
70+ deadline ,
71+ options . payload ?? ZeroHash ,
72+ _overrides ,
73+ options . gatewayAddress ,
74+ String ( options . gatewayBasisPoints ) ,
75+ )
76+ : l2 . swapEthAndStakeDevPolygonCaller (
77+ options . destination ,
78+ ethAmount ,
79+ deadline ,
80+ options . payload ?? ZeroHash ,
81+ _overrides ,
82+ )
83+ } ,
84+ } )
85+ } ) ,
86+ }
87+ : ( undefined as never )
88+ }
0 commit comments