@@ -20,12 +20,13 @@ import {
20
20
21
21
export function coinsToUnits ( asset : SwapAsset | ReferenceAsset , value : string | number , options : Partial < {
22
22
roundUp : boolean ,
23
- treatUsdcAsMatic : boolean ,
23
+ treatPolygonTokenAsMatic : boolean ,
24
24
} > = { } ) : number {
25
25
let decimals = Precision [ asset ] as number ;
26
26
27
- // Some fees for USDC are provided in MATIC, and must be converted accordingly
28
- if ( ( asset === SwapAsset . USDC || asset === SwapAsset . USDC_MATIC ) && options . treatUsdcAsMatic ) decimals = 18 ;
27
+ // Some fees for USDC/T are provided in MATIC, and must be converted accordingly
28
+ const isPolygonToken = asset === SwapAsset . USDC || asset === SwapAsset . USDC_MATIC || asset === SwapAsset . USDT ;
29
+ if ( isPolygonToken && options . treatPolygonTokenAsMatic ) decimals = 18 ;
29
30
30
31
if ( typeof decimals === 'undefined' ) throw new Error ( `Invalid asset ${ asset } ` ) ;
31
32
@@ -50,7 +51,7 @@ export function convertFromData(from: FastspotPrice): PriceData {
50
51
? {
51
52
feePerUnit : coinsToUnits ( asset , from . fundingNetworkFee . perUnit , {
52
53
roundUp : true ,
53
- treatUsdcAsMatic : true ,
54
+ treatPolygonTokenAsMatic : true ,
54
55
} ) ,
55
56
}
56
57
: { } ) ,
@@ -69,7 +70,7 @@ export function convertToData(to: FastspotPrice): PriceData {
69
70
? {
70
71
feePerUnit : coinsToUnits ( asset , to . finalizeNetworkFee . perUnit , {
71
72
roundUp : true ,
72
- treatUsdcAsMatic : true ,
73
+ treatPolygonTokenAsMatic : true ,
73
74
} ) ,
74
75
}
75
76
: { } ) ,
@@ -100,10 +101,15 @@ export function convertContract<T extends SwapAsset>(contract: FastspotContract<
100
101
break ;
101
102
case SwapAsset . USDC :
102
103
case SwapAsset . USDC_MATIC :
104
+ case SwapAsset . USDT :
103
105
htlc = {
104
106
address : contract . id . substring ( 0 , 2 ) === '0x' ? contract . id : `0x${ contract . id } ` ,
105
- contract : ( contract as FastspotContract < SwapAsset . USDC | SwapAsset . USDC_MATIC > ) . intermediary . address ,
106
- data : ( contract as FastspotContract < SwapAsset . USDC | SwapAsset . USDC_MATIC > ) . intermediary . data ,
107
+ contract :
108
+ ( contract as FastspotContract < SwapAsset . USDC | SwapAsset . USDC_MATIC | SwapAsset . USDT > ) . intermediary
109
+ . address ,
110
+ data :
111
+ ( contract as FastspotContract < SwapAsset . USDC | SwapAsset . USDC_MATIC | SwapAsset . USDT > ) . intermediary
112
+ . data ,
107
113
} ;
108
114
break ;
109
115
case SwapAsset . EUR :
@@ -122,7 +128,9 @@ export function convertContract<T extends SwapAsset>(contract: FastspotContract<
122
128
refundAddress : contract . refund ?. address || '' ,
123
129
redeemAddress : contract . asset === SwapAsset . EUR
124
130
? JSON . stringify ( ( contract as FastspotContract < SwapAsset . EUR > ) . recipient )
125
- : ( contract as FastspotContract < SwapAsset . NIM | SwapAsset . BTC | SwapAsset . USDC | SwapAsset . USDC_MATIC > )
131
+ : ( contract as FastspotContract <
132
+ SwapAsset . NIM | SwapAsset . BTC | SwapAsset . USDC | SwapAsset . USDC_MATIC | SwapAsset . USDT
133
+ > )
126
134
. recipient . address ,
127
135
amount : coinsToUnits ( contract . asset , contract . amount ) ,
128
136
timeout : contract . timeout ,
0 commit comments