Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jon/worst-quote #340

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- added: `minReceiveAmount` passed in `EdgeSwapQuotes` for lifi and rango

## 2.7.5 (2024-08-12)

- fixed: Implemented max quotes for 0xGasless swap plugin
Expand Down
15 changes: 8 additions & 7 deletions src/swap/defi/lifi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const asExchangeInfo = asObject({
const asEstimate = asObject({
fromAmount: asNumberString, // "400000",
toAmount: asNumberString, // "237318132569913",
// toAmountMin: asNumberString, // "225452225941418",
toAmountMin: asNumberString, // "225452225941418",
approvalAddress: asString, // "0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE",
executionDuration: asNumber // 1168,
// feeCosts: asArray(asFeeCost)
Expand Down Expand Up @@ -320,7 +320,7 @@ export function makeLifiPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
const providers = includedSteps.map(s => s.toolDetails.name)
const providersStr = providers.join(' -> ')
const metadataNotes = `DEX Providers: ${providersStr}`
const { approvalAddress, toAmount } = estimate
const { approvalAddress, toAmount, toAmountMin } = estimate

let preTx: EdgeTransaction | undefined
let spendInfo: EdgeSpendInfo
Expand Down Expand Up @@ -459,13 +459,14 @@ export function makeLifiPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
}

return {
request,
spendInfo,
swapInfo,
fromNativeAmount: nativeAmount,
expirationDate: new Date(Date.now() + EXPIRATION_MS),
fromNativeAmount: nativeAmount,
metadataNotes,
minReceiveAmount: toAmountMin,
preTx,
metadataNotes
request,
spendInfo,
swapInfo
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/swap/defi/rango.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,14 @@ export function makeRangoPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
const metadataNotes = `DEX Providers: ${providersStr}`

return {
request,
spendInfo,
swapInfo,
fromNativeAmount: nativeAmount,
expirationDate: new Date(Date.now() + EXPIRATION_MS),
fromNativeAmount: nativeAmount,
metadataNotes,
minReceiveAmount: route.outputAmountMin,
preTx,
metadataNotes
request,
spendInfo,
swapInfo
}
}

Expand Down
33 changes: 18 additions & 15 deletions src/util/swapHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ type SwapOrderInner = SwapOrderMakeTx | SwapOrderSpendInfo
export type SwapOrder = SwapOrderInner & {
addTxidToOrderUri?: boolean
canBePartial?: boolean
expirationDate?: Date
fromNativeAmount: string
maxFulfillmentSeconds?: number
metadataNotes?: string
minReceiveAmount?: string
preTx?: EdgeTransaction
request: EdgeSwapRequestPlugin
swapInfo: EdgeSwapInfo
fromNativeAmount: string
expirationDate?: Date
preTx?: EdgeTransaction
metadataNotes?: string
}

export async function makeSwapPluginQuote(
Expand All @@ -61,13 +62,14 @@ export async function makeSwapPluginQuote(
const {
addTxidToOrderUri = false,
canBePartial,
maxFulfillmentSeconds,
fromNativeAmount,
request,
swapInfo,
expirationDate,
fromNativeAmount,
maxFulfillmentSeconds,
metadataNotes,
minReceiveAmount,
preTx,
metadataNotes
request,
swapInfo
} = order
const { fromWallet, toWallet } = request

Expand Down Expand Up @@ -121,18 +123,19 @@ export async function makeSwapPluginQuote(

const out: EdgeSwapQuote = {
canBePartial,
maxFulfillmentSeconds,
request,
swapInfo,
expirationDate,
fromNativeAmount,
toNativeAmount,
isEstimate,
maxFulfillmentSeconds,
minReceiveAmount,
networkFee: {
currencyCode: fromWallet.currencyInfo.currencyCode,
nativeAmount
},
pluginId: swapInfo.pluginId,
expirationDate,
isEstimate,
request,
swapInfo,
toNativeAmount,
async approve(opts?: EdgeSwapApproveOptions): Promise<EdgeSwapResult> {
if (preTx != null) {
const signedTransaction = await fromWallet.signTx(preTx)
Expand Down
Loading