Skip to content
Draft
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
7 changes: 3 additions & 4 deletions functions/api/openocean/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
tac: '0xBBAFF3Bf6eC4C15992c0Fb37F12491Fd62C5B496',
ethereum: '0x60917e542aDdd13bfd1a7f81cD654758052dAdC4',
};
const referrerFee = '0.25';

Check warning on line 7 in functions/api/openocean/index.ts

View workflow job for this annotation

GitHub Actions / Lint (20.x)

'referrerFee' is assigned a value but never used. Allowed unused vars must match /^_/u

const proOrigin = 'https://open-api-pro.openocean.finance/v4';
const allowedEndpoints = ['reverseQuote', 'quote', 'swap', 'gasPrice'];
Expand Down Expand Up @@ -43,16 +43,15 @@
throw new Error(`Unsupported VITE_NETWORK: ${chain}`);
}

const referrer = referrers[network];

// Copy search params from request to openocean
for (const [key, value] of searchParams.entries()) {
url.searchParams.set(key, value);
}

if (endpoint === 'swap') {
url.searchParams.set('referrer', referrer);
url.searchParams.set('referrerFee', referrerFee);
const referrer = referrers[network];

Check warning on line 52 in functions/api/openocean/index.ts

View workflow job for this annotation

GitHub Actions / Lint (20.x)

'referrer' is assigned a value but never used. Allowed unused vars must match /^_/u
// url.searchParams.set('referrer', referrer);
// url.searchParams.set('referrerFee', referrerFee);
}

const response = await fetch(url, {
Expand Down
2 changes: 1 addition & 1 deletion src/config/ethereum/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const commonConfig: AppConfig = {
showCart: true,
// rewardUrl: 'https://app.merkl.xyz/?chain=1&protocol=carbon',
// walkthroughId: 'i2ok96zcpzqw',
useOpenocean: false, // !navigator.webdriver, // use sdk in E2E
useOpenocean: !navigator.webdriver, // use sdk in E2E
useEIP7702: false,
},
};
2 changes: 1 addition & 1 deletion src/config/sei/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ export const commonConfig: AppConfig = {
showCart: true,
// rewardUrl: 'https://app.merkl.xyz/?chain=1329&protocol=carbon',
// walkthroughId: '51xep69sd3io',
useOpenocean: false, // true,
useOpenocean: true,
},
};
23 changes: 14 additions & 9 deletions src/libs/queries/sdk/trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useStore } from 'store';
import { Token } from 'libs/tokens';
import { TransactionRequest } from 'ethers';
import config from 'config';
import { useBatchTransaction } from 'libs/wagmi/batch-transaction';

interface GetTradeDataResult {
tradeActions: TradeActionBNStr[];
Expand Down Expand Up @@ -51,6 +52,7 @@ export const useTradeQuery = () => {
trade: { settings },
} = useStore();
const { signer } = useWagmi();
const { canBatchTransactions } = useBatchTransaction();
return useMutation({
mutationFn: async (params: TradeParams) => {
const { calcDeadline, calcMinReturn, calcMaxInput } = params;
Expand All @@ -72,17 +74,20 @@ export const useTradeQuery = () => {
value: BigInt(tx.value),
data: tx.data,
};
// Bump estimated gas because openocean isn't working correctly
const estimateGas = await signer?.estimateGas(unsignedTx);
if (estimateGas) {
const limit = new SafeDecimal(estimateGas?.toString())
.mul(1.1)
.round()
.toString();
unsignedTx.gasLimit = BigInt(limit);
// If tokens are not approved, the estimate gas will fail with EIP7702
if (!canBatchTransactions) {
// Bump estimated gas because openocean isn't working correctly
const estimateGas = await signer?.estimateGas(unsignedTx);
if (estimateGas) {
const limit = new SafeDecimal(estimateGas?.toString())
.mul(1.1)
.round()
.toString();
unsignedTx.gasLimit = BigInt(limit);
}
}
unsignedTx.customData = {
spender: config.addresses.carbon.carbonController,
spender: config.addresses.openocean,
assets: [
{
address: params.source.address,
Expand Down
Loading