Skip to content

Commit 1aaf665

Browse files
authored
Merge pull request #33 from safeblock-dev/feat/units
Update the default entry point contract address on the units network …
2 parents 6a1a66d + f32cfb0 commit 1aaf665

File tree

10 files changed

+45
-46
lines changed

10 files changed

+45
-46
lines changed

package-lock.json

Lines changed: 23 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
"url": "https://github.com/safeblock-dev/exchange-sdk/issues"
6161
},
6262
"homepage": "https://github.com/safeblock-dev/exchange-sdk#readme",
63-
"dependencies": {
64-
"@safeblock/blockchain-utils": "^1.0.0",
63+
"peerDependencies": {
64+
"@safeblock/blockchain-utils": "^1.0.2",
6565
"ethers": "^6.15.0"
6666
}
6767
}

src/__specs__/single-chain-ethereum.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Address, Amount } from "@safeblock/blockchain-utils"
2+
import { describe, expect, it } from "vitest"
23
import runSingleChainTests from "~/__specs__/utils/run-single-chain-tests"
34
import { PriceStorageExtension } from "~/extensions"
45
import { SdkException } from "~/index"
5-
import { bnbDAI, bnbUSDT, sdkConfig } from "./utils/sdk-test-config"
66
import SafeBlockSDK from "~/sdk"
77
import { ExchangeRequest } from "~/types"
8-
import { describe, expect, it } from "vitest"
8+
import { bnbDAI, bnbUSDT, sdkConfig } from "./utils/sdk-test-config"
99

1010
describe("Single chain exchanges in Ethereum networks", async () => {
1111
const sdk = new SafeBlockSDK(sdkConfig)

src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { SdkConfig } from "~/sdk"
66
const contractAddresses = {
77
entryPoint: (network: Network, config?: SdkConfig) => selectAddress(network, config?.contractAddresses?.entryPoint ?? {
88
default: "0xA5487594bD2303AF225f8c15E80CED0Da883A0E8",
9-
[units.name]: "0xA26c8aC451d9EBbd4B40e8D2Ed91f5c55b989001"
9+
[units.name]: "0x65DfbA5338137e0De3c7e9C11D9BFEd0B02c33b8"
1010
}),
1111

1212
quoter: (network: Network, config?: SdkConfig) => selectAddress(network, config?.contractAddresses?.quoter ?? {
@@ -16,7 +16,7 @@ const contractAddresses = {
1616

1717
offchainOracle: (network: Network) => selectAddress(network, {
1818
[scroll.name]: "0xA2a3F952427c22e208a8298fd2346B8e664964b1",
19-
[units.name]: "0x16a35020a2D45f80cc156649D57E4Cc9d4fC74D2",
19+
[units.name]: "0xdd4ec4bFecAb02CbE60CdBA8De49821a1105c24f",
2020
default: "0x00000000000D6FFc74A8feb35aF5827bf57f6786"
2121
}),
2222

src/extensions/price-storage-extension.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Address, Amount, arrayUtils, multicall, MultiCallRequest, units } from "@safeblock/blockchain-utils"
1+
import { Address, Amount, arrayUtils, multicall, MultiCallRequest } from "@safeblock/blockchain-utils"
22
import { Network } from "ethers"
33
import { OffchainOracle__factory } from "~/abis/types"
44
import { contractAddresses } from "~/config"
@@ -242,13 +242,7 @@ export default class PriceStorageExtension extends SdkExtension {
242242
if (task !== this.#currentFetchingTask) return
243243

244244
const usdcRate = rates.find((r) => Address.equal(r.token.address, usdc.address))?.rate
245-
if (!usdcRate) {
246-
if (network.name === units.name) {
247-
this._prices.get(network.name)?.set(usdc.address.toString().toLowerCase(), BigInt(1e6))
248-
}
249-
250-
return
251-
}
245+
if (!usdcRate) return
252246

253247
rates.forEach((rate) => {
254248
if (Address.equal(rate.token.address, usdc.address)) {

src/sdk/evm-converter/evm-converter.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ export default class EvmConverter extends ExchangeConverter {
221221
headers: this.sdkConfig.backend?.headers,
222222
bannedDexIds: this.sdkInstance.dexBlacklist.toArray(),
223223
fromToken: request.tokenIn,
224-
toToken: tokenOut,
225-
amountInRaw: smartRoutingAvailable ? request.amountIn.toString() : undefined
224+
toToken: tokenOut
226225
})
227226
))
228227
))

src/sdk/evm-converter/evm-cross-chain-extension.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export default class EvmCrossChainExtension {
3434

3535
if (_request instanceof SdkException) return _request
3636

37+
if (request.tokenIn.network.name === units.name || request.tokensOut.some(token => token.network.name === units.name))
38+
return new SdkException("Cross-chain swaps with units network not supported", SdkExceptionCode.InvalidRequest)
39+
3740
if (_request.exactInput) return this.createMultiChainExchangeTransactionLTR(from, _request, taskId)
3841

3942
return this.createMultiChainExchangeTransactionRTL(from, _request, taskId)
@@ -460,7 +463,7 @@ export default class EvmCrossChainExtension {
460463
)),
461464
smartRoutingEstimatedGasUsage: smGasUsage.gt(0) ? smGasUsage.toFixed(0) : undefined
462465
}
463-
466+
464467
return mixin.applyMixin("quotaComputationFinalized", {
465468
...rawQuota,
466469
estimatedGasUsage: ExchangeUtils.computeQuotaExecutionGasUsage(rawQuota, this.mixins)

src/utils/get-exchange-routes.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Address, arrayUtils } from "@safeblock/blockchain-utils"
22
import { BackendResponse, BasicToken, RouteStep } from "~/types"
33
import LimitedMap from "~/utils/limited-map"
44
import request from "~/utils/request"
5-
import IBackendRouteStep = BackendResponse.IBackendRouteStep
65
import IRoutesResponse = BackendResponse.IRoutesResponse
76
import IRoutesResponseNext = BackendResponse.IRoutesResponseNext
87

@@ -14,7 +13,6 @@ interface Options {
1413
headers?: Record<string, string>
1514
routeCacheTime?: number
1615

17-
amountInRaw?: string
1816
epsilon?: number
1917
maxPairsCount?: number
2018

@@ -29,7 +27,7 @@ export default async function getExchangeRoutes(options: Options): Promise<{ rou
2927
const routeKey = options.fromToken.address.toString() + options.toToken.address.toString()
3028
+ options.fromToken.network.name + options.toToken.network.name
3129
+ options.bannedDexIds?.join(",")
32-
+ options.amountInRaw + options.epsilon + options.maxPairsCount
30+
+ options.epsilon + options.maxPairsCount
3331

3432
const cachedRoute = routesCache.get(routeKey)
3533

@@ -47,7 +45,6 @@ export default async function getExchangeRoutes(options: Options): Promise<{ rou
4745
limit: 30,
4846
network: fromToken.network.chainId.toString(),
4947
banned_dex_ids: bannedDexIds?.length ? bannedDexIds.join(",") : null,
50-
amount: options.amountInRaw,
5148
epsilon: options.epsilon || null,
5249
max_pairs_count: options.maxPairsCount || null
5350
}
@@ -58,18 +55,9 @@ export default async function getExchangeRoutes(options: Options): Promise<{ rou
5855

5956
if (!rawRoutes) return { routes: [], percents: [] }
6057

61-
let plainRoutesList: IBackendRouteStep[][]
58+
const _rawRoutes = rawRoutes as BackendResponse.IRoutesResponse
6259

63-
if (options.amountInRaw) {
64-
const _rawRoutes = rawRoutes as BackendResponse.IRoutesResponseNext
65-
66-
plainRoutesList = _rawRoutes.route
67-
}
68-
else {
69-
const _rawRoutes = rawRoutes as BackendResponse.IRoutesResponse
70-
71-
plainRoutesList = [..._rawRoutes.items.swap.map(route => [route]), ..._rawRoutes.items.multiswap]
72-
}
60+
const plainRoutesList = [..._rawRoutes.items.swap.map(route => [route]), ..._rawRoutes.items.multiswap]
7361

7462
if (!plainRoutesList || plainRoutesList.length === 0) return { routes: [], percents: [] }
7563

src/utils/safeblock-mappings.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { arbitrum, avalanche, base, bnb, gnosis, mainnet, matic, optimism, scroll } from "@safeblock/blockchain-utils"
1+
import { arbitrum, avalanche, base, bnb, gnosis, mainnet, matic, optimism, scroll, units } from "@safeblock/blockchain-utils"
22
import { Network } from "ethers"
33
import { SdkConfig } from "~/sdk"
44

@@ -11,7 +11,8 @@ const SafeblockNetworksMap: Record<string, Network> = {
1111
"optimism": optimism,
1212
"base": base,
1313
"gnosis": gnosis,
14-
"scroll": scroll
14+
"scroll": scroll,
15+
"units": units
1516
}
1617

1718
/** Function for converting internal `SafeBlock` network names to `ethers`-compatible names */

vitest.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import * as path from "node:path"
22
import { defineConfig } from "vitest/config"
33

44
export default defineConfig({
5+
test: {
6+
testTimeout: 30_000
7+
},
58
resolve: {
69
alias: [
710
{ find: "~", replacement: path.resolve(__dirname, "./src/") }

0 commit comments

Comments
 (0)