Skip to content

Commit 0b56354

Browse files
committed
add oku uniswap on bob
1 parent c81e1b4 commit 0b56354

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

src/swapService/strategies/balmySDK/customSourceList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const customSources = {
2929
"IceCreamSwap",
3030
[60808],
3131
),
32-
// oku_bob_uniswap: new CustomOkuQuoteSource("usor", "Uniswap", [60808]),
32+
oku_bob_uniswap: new CustomOkuQuoteSource("usor", "Uniswap", [60808]),
3333
}
3434
export class CustomSourceList extends LocalSourceList {
3535
constructor({ providerService, fetchService }: ConstructorParameters) {

src/swapService/strategies/balmySDK/okuQuoteSource.ts

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,20 @@ import {
2424
calculateAllowanceTarget,
2525
failed,
2626
} from "@balmy/sdk/dist/services/quotes/quote-sources/utils"
27-
import { type Address as ViemAddress, formatUnits, parseUnits } from "viem"
27+
import type { Hex } from "@berachain-foundation/berancer-sdk"
28+
import {
29+
type Address as ViemAddress,
30+
encodeFunctionData,
31+
formatUnits,
32+
parseAbi,
33+
parseUnits,
34+
} from "viem"
2835

29-
const CHAINS: Record<ChainId, string> = {
30-
[60808]: "bob",
36+
const CHAINS: Record<ChainId, Record<string, string>> = {
37+
[60808]: {
38+
key: "bob",
39+
permit2Adapter: "0xcBF002A9eB906F35eA35aD0634CC5f3d85a10426",
40+
},
3141
}
3242

3343
const OKU_METADATA: QuoteSourceMetadata<OkuSupport> = {
@@ -68,7 +78,7 @@ export class CustomOkuQuoteSource extends AlwaysValidConfigAndContextSource<
6878
getMetadata() {
6979
return {
7080
...OKU_METADATA,
71-
// name: `${OKU_METADATA.name} ${this.marketName}`,
81+
name: `${OKU_METADATA.name} ${this.marketName}`,
7282
supports: {
7383
...OKU_METADATA.supports,
7484
chains: this.chains || OKU_METADATA.supports.chains,
@@ -106,9 +116,11 @@ export class CustomOkuQuoteSource extends AlwaysValidConfigAndContextSource<
106116
external.gasPrice.request(),
107117
external.tokenData.request(),
108118
])
119+
109120
const body = {
110-
chain: CHAINS[chainId],
111-
account: takeFrom,
121+
chain: CHAINS[chainId].key,
122+
account:
123+
this.market === "usor" ? CHAINS[chainId].permit2Adapter : takeFrom,
112124
gasPrice: Number(eip1159ToLegacy(gasPrice)),
113125
isExactIn: order.type === "sell",
114126
inTokenAddress: mapToken(sellToken),
@@ -174,6 +186,28 @@ export class CustomOkuQuoteSource extends AlwaysValidConfigAndContextSource<
174186
async buildTx({
175187
request,
176188
}: BuildTxParams<OkuConfig, OkuData>): Promise<SourceQuoteTransaction> {
189+
if (this.market === "usor") {
190+
const adapterAbi = parseAbi([
191+
"function swap(address target, address token, uint256 amount, uint256 sweepAmountMin, bytes calldata data)",
192+
])
193+
const calldata = encodeFunctionData({
194+
abi: adapterAbi,
195+
functionName: "swap",
196+
args: [
197+
request.customData.tx.to as Hex,
198+
request.sellToken as Hex,
199+
request.maxSellAmount,
200+
5n,
201+
request.customData.tx.calldata as Hex,
202+
],
203+
})
204+
return {
205+
to: CHAINS[request.chainId].permit2Adapter,
206+
calldata,
207+
value: request.customData.tx.value,
208+
}
209+
}
210+
177211
return request.customData.tx
178212
}
179213
}

0 commit comments

Comments
 (0)