Skip to content

Commit

Permalink
fixup! Implement 0x gasless swap plugin without approve
Browse files Browse the repository at this point in the history
  • Loading branch information
samholmes committed Jun 25, 2024
1 parent 57cbc1b commit 548fa0b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { makeLetsExchangePlugin } from './swap/central/letsexchange'
import { makeSideshiftPlugin } from './swap/central/sideshift'
import { makeSwapuzPlugin } from './swap/central/swapuz'
import { make0xPlugin } from './swap/defi/0x/0x'
import { make0xGaslessSwap } from './swap/defi/0x/0xGaslessSwap'
import { make0xGaslessPlugin } from './swap/defi/0x/0xGasless'
import { makeCosmosIbcPlugin } from './swap/defi/cosmosIbc'
import { makeLifiPlugin } from './swap/defi/lifi'
import { makeThorchainPlugin } from './swap/defi/thorchain'
Expand Down Expand Up @@ -39,7 +39,7 @@ const plugins = {
transfer: makeTransferPlugin,
velodrome: makeVelodromePlugin,
xrpdex,
zeroxgaslessswap: make0xGaslessSwap,
'0xgasless': make0xGaslessPlugin,
'0x': make0xPlugin
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { add } from 'biggystring'
import {
EdgeCorePluginFactory,
EdgeNetworkFee,
EdgeSwapApproveOptions,
EdgeSwapInfo,
EdgeSwapPlugin,
EdgeSwapQuote,
EdgeSwapResult
} from 'edge-core-js/types'
Expand All @@ -16,13 +14,11 @@ import { getCurrencyCode, getTokenAddress } from './util'

const swapInfo: EdgeSwapInfo = {
displayName: '0x Gasless Swap',
pluginId: 'zeroxgaslessswap',
pluginId: '0xgasless',
supportEmail: '[email protected]'
}

export const make0xGaslessSwap: EdgeCorePluginFactory = (
opts
): EdgeSwapPlugin => {
export const make0xGaslessPlugin: EdgeCorePluginFactory = opts => {
const { io } = opts
const initOptions = asInitOptions(opts.initOptions)

Expand All @@ -44,10 +40,6 @@ export const make0xGaslessSwap: EdgeCorePluginFactory = (
swapRequest.fromWallet,
swapRequest.fromTokenId
)
const fromCurrencyCode = getCurrencyCode(
swapRequest.fromWallet,
swapRequest.fromTokenId
)
const toTokenAddress = getTokenAddress(
swapRequest.toWallet,
swapRequest.toTokenId
Expand Down Expand Up @@ -95,11 +87,6 @@ export const make0xGaslessSwap: EdgeCorePluginFactory = (
)
}

const networkFee: EdgeNetworkFee = {
currencyCode: fromCurrencyCode,
nativeAmount: add(gasFee.feeAmount, zeroExFee.feeAmount)
}

return {
approve: async (
opts?: EdgeSwapApproveOptions
Expand All @@ -110,7 +97,13 @@ export const make0xGaslessSwap: EdgeCorePluginFactory = (
expirationDate: new Date(Date.now() + EXPIRATION_MS),
fromNativeAmount: apiSwapQuote.sellAmount,
isEstimate: false,
networkFee,
networkFee: {
currencyCode: getCurrencyCode(
swapRequest.fromWallet,
swapRequest.fromTokenId
),
nativeAmount: add(gasFee.feeAmount, zeroExFee.feeAmount)
},
pluginId: swapInfo.pluginId,
request: swapRequest,
swapInfo: swapInfo,
Expand Down

0 comments on commit 548fa0b

Please sign in to comment.