Skip to content

Commit

Permalink
Merge pull request #126 from CityOfZion/CU-86a5y36xd
Browse files Browse the repository at this point in the history
CU-86a5y36xd-BS Lib - Add a 1 percent padding to minimum swap amount …
  • Loading branch information
thiagocbalducci authored Dec 17, 2024
2 parents f4fa6d9 + 7b3e120 commit fbc9a4b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-swap",
"comment": "Add 1% in SimpleSwap minimum",
"type": "patch"
}
],
"packageName": "@cityofzion/bs-swap"
}
2 changes: 1 addition & 1 deletion packages/bs-swap/src/__tests__/SimpleSwapApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ describe('SimpleSwapApi', () => {
log: expect.any(String),
})
)
})
}, 10000)
})
2 changes: 1 addition & 1 deletion packages/bs-swap/src/__tests__/SimpleSwapService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ describe('SimpleSwapService', () => {
expect(amountToReceive).toEqual({ loading: false, value: null })
expect(addressToReceive).toEqual({ loading: false, value: null, valid: null })
expect(amountToUseMinMax).toEqual({ loading: false, value: null })
})
}, 10000)

it('Should be able to set the token to receive', async () => {
await simpleSwapService.init()
Expand Down
8 changes: 5 additions & 3 deletions packages/bs-swap/src/services/SimpleSwapService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,12 @@ export class SimpleSwapService<BSName extends string = string> implements SwapSe

if ((shouldRecalculateAmountToUseMinMax || range === null) && this.#tokenToReceive.value) {
const apiRange = await this.#api.getRange(this.#tokenToUse.value, this.#tokenToReceive.value)

// Add 1% because the SimpleSwap sends us a smaller minimum
const rangeMin = (+apiRange.min * 1.01).toString()

range = {
min: this.#tokenToUse.value.decimals
? formatNumber(apiRange.min, this.#tokenToUse.value.decimals)
: apiRange.min,
min: this.#tokenToUse.value.decimals ? formatNumber(rangeMin, this.#tokenToUse.value.decimals) : rangeMin,
max:
this.#tokenToUse.value.decimals && apiRange.max
? formatNumber(apiRange.max, this.#tokenToUse.value.decimals)
Expand Down

0 comments on commit fbc9a4b

Please sign in to comment.