Skip to content

Commit 890e788

Browse files
authored
Merge pull request #401 from EdgeApp/sam/sui
feat(lifi): add SUI blockchain support
2 parents 5219627 + 257bbba commit 890e788

File tree

3 files changed

+82
-8
lines changed

3 files changed

+82
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- added: (LI.FI) Add SUI blockchain support for swaps via Aftermath and Bluefin7k DEXs
6+
57
## 2.33.0 (2025-09-09)
68

79
- added: Add Bridgeless plugin

src/swap/defi/lifi.ts

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
SwapBelowLimitError,
1919
SwapCurrencyError
2020
} from 'edge-core-js/types'
21+
import { base64 } from 'rfc4648'
2122

2223
import { div18 } from '../../util/biggystringplus'
2324
import {
@@ -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'
4046
import { getEvmApprovalData, WEI_MULTIPLIER } from './defiUtils'
4147

4248
const 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+
186202
const 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),

src/util/swapHelpers.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,17 @@ export async function makeSwapPluginQuote(
8585
// Handle the new MakeTx type for SUI
8686
if (makeTxParams.type === 'MakeTx') {
8787
tx = await fromWallet.otherMethods.makeTx(makeTxParams)
88-
if (tx.savedAction == null) {
89-
tx.savedAction = makeTxParams.metadata?.savedAction
88+
if (
89+
tx.savedAction == null &&
90+
makeTxParams.metadata?.savedAction != null
91+
) {
92+
tx.savedAction = makeTxParams.metadata.savedAction
9093
}
91-
if (tx.assetAction == null) {
92-
tx.assetAction = makeTxParams.metadata?.assetAction
94+
if (
95+
tx.assetAction == null &&
96+
makeTxParams.metadata?.assetAction != null
97+
) {
98+
tx.assetAction = makeTxParams.metadata.assetAction
9399
}
94100
} else {
95101
const { assetAction, savedAction } = makeTxParams
@@ -103,7 +109,6 @@ export async function makeSwapPluginQuote(
103109
tx.assetAction = assetAction
104110
}
105111
}
106-
107112
if (tx.tokenId == null) {
108113
tx.tokenId = request.fromTokenId
109114
}
@@ -277,7 +282,7 @@ export const customFeeCache = {
277282
setFees: (uid: string, customNetworkFee?: JsonObject): void => {
278283
for (const id of Object.keys(customFeeCacheMap)) {
279284
if (Date.now() > customFeeCacheMap[id].timestamp + 30000) {
280-
delete customFeeCacheMap[id] // eslint-disable-line
285+
delete customFeeCacheMap[id]; // eslint-disable-line
281286
}
282287
}
283288
customFeeCacheMap[uid] = { customNetworkFee, timestamp: Date.now() }

0 commit comments

Comments
 (0)