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

Upgrade node; getPriceForAmount updates #1243

Merged
merged 4 commits into from
Jan 3, 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: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
18.15
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@
"typescript": "^5.0.4"
},
"engines": {
"node": ">= 18"
"node": ">= 18.15"
}
}
2 changes: 1 addition & 1 deletion source/balances/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion source/pool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion source/registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion source/staking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"access": "public"
},
"devDependencies": {
"@airswap/utils": "4.1.11",
"@airswap/utils": "4.1.12",
"prompt-confirm": "^2.0.4"
}
}
2 changes: 1 addition & 1 deletion source/swap-erc20/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion source/swap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion source/wrapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tools/libraries/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airswap/libraries",
"version": "4.1.16",
"version": "4.1.17",
"description": "AirSwap: Libraries for Developers",
"repository": {
"type": "git",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tools/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airswap/utils",
"version": "4.1.11",
"version": "4.1.12",
"description": "AirSwap: Utilities for Developers",
"repository": {
"type": "git",
Expand Down
18 changes: 14 additions & 4 deletions tools/utils/src/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Loading