Skip to content

Commit 68413ad

Browse files
committed
remove gas price calls
1 parent 9e3cbb2 commit 68413ad

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type {
2+
ChainId,
3+
FieldsRequirements,
4+
IProviderService,
5+
SupportRecord,
6+
TimeString,
7+
} from "@balmy/sdk"
8+
import type {
9+
GasPriceResult,
10+
GasValueForVersions,
11+
IGasPriceSource,
12+
} from "@balmy/sdk/dist/services/gas/types"
13+
14+
// Stub out gas price calculations to make sure not to hit RPCs
15+
type GasValues = GasValueForVersions<"standard">
16+
export class StubGasPriceSource implements IGasPriceSource<GasValues> {
17+
constructor(private readonly providerService: IProviderService) {}
18+
19+
supportedSpeeds() {
20+
const support: SupportRecord<GasValues> = { standard: "present" }
21+
return Object.fromEntries(
22+
this.providerService
23+
.supportedChains()
24+
.map((chainId) => [Number(chainId), support]),
25+
)
26+
}
27+
28+
getGasPrice<Requirements extends FieldsRequirements<GasValues>>() {
29+
return Promise.resolve({
30+
standard: {
31+
maxFeePerGas: 0,
32+
maxPriorityFeePerGas: 0,
33+
gasPrice: 0,
34+
},
35+
}) as unknown as Promise<GasPriceResult<GasValues, Requirements>>
36+
}
37+
}

src/swapService/strategies/strategyBalmySDK.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
quoteToRoute,
4141
} from "../utils"
4242
import { CustomSourceList } from "./balmySDK/customSourceList"
43+
import { StubGasPriceSource } from "./balmySDK/stubGasPriceSource"
4344
import { TokenlistMetadataSource } from "./balmySDK/tokenlistMetadataSource"
4445

4546
const DAO_MULTISIG = "0xcAD001c30E96765aC90307669d578219D4fb1DCe"
@@ -88,7 +89,15 @@ export class StrategyBalmySDK {
8889
constructor(match = {}, config?: BalmyStrategyConfig) {
8990
this.config = { ...defaultConfig, ...(config || {}) }
9091
const fetchService = buildFetchService()
91-
const providerService = buildProviderService()
92+
const providerService = buildProviderService({
93+
source: {
94+
type: "public-rpcs",
95+
rpcsPerChain: combinePublicAndPrivateRPCs(),
96+
config: {
97+
type: "fallback",
98+
},
99+
},
100+
})
92101

93102
const buildParams: BuildParams = {
94103
quotes: {
@@ -153,6 +162,12 @@ export class StrategyBalmySDK {
153162
},
154163
},
155164
},
165+
gas: {
166+
source: {
167+
type: "custom",
168+
instance: new StubGasPriceSource(providerService),
169+
},
170+
},
156171
} as BuildParams
157172
this.sdk = buildSDK(buildParams)
158173
this.match = match

0 commit comments

Comments
 (0)