diff --git a/.nvmrc b/.nvmrc index da2d3988d..0f9eb8244 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -14 \ No newline at end of file +18.15 \ No newline at end of file diff --git a/package.json b/package.json index 72eb52902..946a33598 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,6 @@ "typescript": "^5.0.4" }, "engines": { - "node": ">= 18" + "node": ">= 18.15" } } diff --git a/source/balances/package.json b/source/balances/package.json index cfeebdb54..223235d27 100644 --- a/source/balances/package.json +++ b/source/balances/package.json @@ -30,7 +30,7 @@ }, "devDependencies": { "@airswap/constants": "4.1.8", - "@airswap/utils": "4.1.11", + "@airswap/utils": "4.1.12", "prompt-confirm": "^2.0.4" }, "publishConfig": { diff --git a/source/pool/package.json b/source/pool/package.json index 0091b8e32..e2e52b172 100644 --- a/source/pool/package.json +++ b/source/pool/package.json @@ -34,7 +34,7 @@ "@airswap/constants": "4.1.8", "@airswap/metadata": "4.1.15", "@airswap/types": "4.1.3", - "@airswap/utils": "4.1.11", + "@airswap/utils": "4.1.12", "prompt-confirm": "^2.0.4" }, "publishConfig": { diff --git a/source/registry/package.json b/source/registry/package.json index 90123f3a3..eb7d5b158 100644 --- a/source/registry/package.json +++ b/source/registry/package.json @@ -33,7 +33,7 @@ }, "devDependencies": { "@airswap/constants": "4.1.8", - "@airswap/utils": "4.1.11", + "@airswap/utils": "4.1.12", "prompt-confirm": "^2.0.4" } } diff --git a/source/staking/package.json b/source/staking/package.json index d327b2d3a..ceef3b34f 100644 --- a/source/staking/package.json +++ b/source/staking/package.json @@ -32,7 +32,7 @@ "access": "public" }, "devDependencies": { - "@airswap/utils": "4.1.11", + "@airswap/utils": "4.1.12", "prompt-confirm": "^2.0.4" } } diff --git a/source/swap-erc20/package.json b/source/swap-erc20/package.json index 9408d20b1..90b6351bd 100644 --- a/source/swap-erc20/package.json +++ b/source/swap-erc20/package.json @@ -32,7 +32,7 @@ "@airswap/constants": "4.1.8", "@airswap/staking": "4.0.5", "@airswap/types": "4.1.3", - "@airswap/utils": "4.1.11", + "@airswap/utils": "4.1.12", "prompt-confirm": "^2.0.4" }, "publishConfig": { diff --git a/source/swap/package.json b/source/swap/package.json index ce388b096..53df5f677 100644 --- a/source/swap/package.json +++ b/source/swap/package.json @@ -34,7 +34,7 @@ "devDependencies": { "@airswap/constants": "4.1.8", "@airswap/types": "4.1.3", - "@airswap/utils": "4.1.11", + "@airswap/utils": "4.1.12", "@nomicfoundation/hardhat-network-helpers": "^1.0.7" }, "publishConfig": { diff --git a/source/wrapper/package.json b/source/wrapper/package.json index a8c0152c6..89ffd21cd 100644 --- a/source/wrapper/package.json +++ b/source/wrapper/package.json @@ -33,7 +33,7 @@ }, "devDependencies": { "@airswap/constants": "4.1.8", - "@airswap/utils": "4.1.11", + "@airswap/utils": "4.1.12", "@airswap/types": "4.1.3", "@uniswap/v2-periphery": "^1.1.0-beta.0", "prompt-confirm": "^2.0.4" diff --git a/tools/libraries/package.json b/tools/libraries/package.json index 438c36385..6c5e8fcb6 100644 --- a/tools/libraries/package.json +++ b/tools/libraries/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/libraries", - "version": "4.1.16", + "version": "4.1.17", "description": "AirSwap: Libraries for Developers", "repository": { "type": "git", @@ -35,7 +35,7 @@ "@airswap/swap": "4.1.2", "@airswap/swap-erc20": "4.1.6", "@airswap/types": "4.1.3", - "@airswap/utils": "4.1.11", + "@airswap/utils": "4.1.12", "@airswap/wrapper": "4.1.5", "browser-or-node": "^2.1.1", "ethers": "^5.6.9", diff --git a/tools/utils/package.json b/tools/utils/package.json index e0ad35e4a..0a88ae5b0 100644 --- a/tools/utils/package.json +++ b/tools/utils/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/utils", - "version": "4.1.11", + "version": "4.1.12", "description": "AirSwap: Utilities for Developers", "repository": { "type": "git", diff --git a/tools/utils/src/pricing.ts b/tools/utils/src/pricing.ts index 349b27967..0dfe3b39f 100644 --- a/tools/utils/src/pricing.ts +++ b/tools/utils/src/pricing.ts @@ -38,16 +38,26 @@ export function getCostFromPricing( for (const i in pricing) { if (pricing[i].baseToken.toLowerCase() === baseToken.toLowerCase()) { if (pricing[i].quoteToken.toLowerCase() === quoteToken.toLowerCase()) { - if (side === 'buy') { - return calculateCost(amount, pricing[i].ask) + if (pricing[i].minimum && BigNumber(amount).lt(pricing[i].minimum)) { + throw new Error( + `Requested amount ${amount} does not meet minimum ${pricing[i].minimum}` + ) + } else { + if (side === 'buy') { + return calculateCost(amount, pricing[i].ask) + } + return calculateCost(amount, pricing[i].bid) } - return calculateCost(amount, pricing[i].bid) } } } - return null + throw new Error( + `Requested pair ${quoteToken}/${baseToken} not found in provided pricing` + ) } +export const getPriceForAmount = getCostFromPricing + export function calculateCost(amount: string, pricing: Formula | Levels) { // TODO: Formula support if (typeof pricing !== 'string') {