@@ -18,6 +18,7 @@ import {
1818 SwapBelowLimitError ,
1919 SwapCurrencyError
2020} from 'edge-core-js/types'
21+ import { base64 } from 'rfc4648'
2122
2223import { div18 } from '../../util/biggystringplus'
2324import {
@@ -36,7 +37,12 @@ import {
3637 makeQueryParams ,
3738 promiseWithTimeout
3839} from '../../util/utils'
39- import { asNumberString , EdgeSwapRequestPlugin , StringMap } from '../types'
40+ import {
41+ asNumberString ,
42+ EdgeSwapRequestPlugin ,
43+ MakeTxParams ,
44+ StringMap
45+ } from '../types'
4046import { getEvmApprovalData , WEI_MULTIPLIER } from './defiUtils'
4147
4248const pluginId = 'lifi'
@@ -72,6 +78,11 @@ const getParentTokenContractAddress = (pluginId: string): string => {
7278 return '11111111111111111111111111111111'
7379 }
7480
81+ // chainType SUI
82+ case 'sui' : {
83+ return '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI'
84+ }
85+
7586 // chainType EVM
7687 case 'celo' : {
7788 return '0x471EcE3750Da237f93B8E339c536989b8978a438'
@@ -117,6 +128,7 @@ const MAINNET_CODE_TRANSCRIPTION: StringMap = {
117128 polygon : 'POL' ,
118129 rsk : 'RSK' ,
119130 solana : 'SOL' ,
131+ sui : 'SUI' ,
120132 velas : 'VEL' ,
121133 zksync : 'ERA'
122134}
@@ -183,6 +195,10 @@ const asTransactionRequestSolana = asObject({
183195 data : asString
184196} )
185197
198+ const asTransactionRequestSui = asObject ( {
199+ data : asString
200+ } )
201+
186202const asIncludedStep = asObject ( {
187203 estimate : asOptional ( asEstimate ) ,
188204 toolDetails : asObject ( {
@@ -405,6 +421,53 @@ export function makeLifiPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
405421
406422 break
407423 }
424+ case 'sui' : {
425+ // SUI uses pre-built transactions via makeTx
426+ const { data } = asTransactionRequestSui ( transactionRequestRaw )
427+
428+ // Convert base64 to Uint8Array for makeTx
429+ const unsignedTx = base64 . parse ( data )
430+
431+ // Create makeTxParams using the new MakeTx type
432+ const makeTxParams : MakeTxParams = {
433+ type : 'MakeTx' ,
434+ unsignedTx,
435+ metadata : {
436+ assetAction : {
437+ assetActionType : 'swap'
438+ } ,
439+ savedAction : {
440+ actionType : 'swap' ,
441+ swapInfo,
442+ isEstimate : true ,
443+ toAsset : {
444+ pluginId : toWallet . currencyInfo . pluginId ,
445+ tokenId : toTokenId ,
446+ nativeAmount : toAmount
447+ } ,
448+ fromAsset : {
449+ pluginId : fromWallet . currencyInfo . pluginId ,
450+ tokenId : fromTokenId ,
451+ nativeAmount : fromAmount
452+ } ,
453+ payoutAddress : toAddress ,
454+ payoutWalletId : toWallet . id ,
455+ refundAddress : fromAddress
456+ }
457+ }
458+ }
459+
460+ // Return SwapOrder with makeTxParams for SUI
461+ return {
462+ expirationDate : new Date ( Date . now ( ) + EXPIRATION_MS ) ,
463+ fromNativeAmount : nativeAmount ,
464+ metadataNotes,
465+ minReceiveAmount : toAmountMin ,
466+ makeTxParams,
467+ request,
468+ swapInfo
469+ }
470+ }
408471 default : {
409472 const transactionRequest = asTransactionRequest ( transactionRequestRaw )
410473 const { data, gasLimit, gasPrice } = transactionRequest
@@ -515,7 +578,11 @@ export function makeLifiPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
515578 if ( request . fromTokenId != null ) {
516579 const maxAmount =
517580 request . fromWallet . balanceMap . get ( request . fromTokenId ) ?? '0'
518- newRequest = { ...request , nativeAmount : maxAmount , quoteFor : 'from' }
581+ newRequest = {
582+ ...request ,
583+ nativeAmount : maxAmount ,
584+ quoteFor : 'from'
585+ }
519586 } else {
520587 newRequest = await getMaxSwappable (
521588 async r => await fetchSwapQuoteInner ( r ) ,
0 commit comments