Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
feat: USDC@Linea added to sample token bucket, protection against cha…
Browse files Browse the repository at this point in the history
…ins where swaps are not avail (#102)
  • Loading branch information
alexeychr authored Aug 9, 2023
1 parent 7ece452 commit a676ad4
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@debridge-finance/dln-executor",
"description": "DLN executor is the rule-based daemon service developed to automatically execute orders placed on the deSwap Liquidity Network (DLN) across supported blockchains",
"version": "2.8.0",
"version": "2.8.1",
"author": "deBridge",
"license": "GPL-3.0-only",
"homepage": "https://debridge.finance",
Expand Down
1 change: 1 addition & 0 deletions sample.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const config: ExecutorLaunchConfig = {
[ChainId.Avalanche]: ["0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E"],
[ChainId.BSC]: ["0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d"],
[ChainId.Ethereum]: ["0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"],
[ChainId.Linea]: ['0x176211869cA2b568f2A7D4EE941E073a821EE1ff'],
[ChainId.Optimism]: ['0x7f5c764cbc14f9669b88837ca1490cca17c31607'],
[ChainId.Polygon]: ["0x2791bca1f2de4661ed88a30c99a7a9449aa84174"],
[ChainId.Solana]: ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"],
Expand Down
5 changes: 5 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export enum SupportedChain {
Optimism = ChainId.Optimism,
}

export enum DexlessChains {
Base = ChainId.Base,
Linea = ChainId.Linea,
}

export class EvmRebroadcastAdapterOpts {
/**
* defines a multiplier to increase a pending txn's gasPrice for pushing it off the mempool.
Expand Down
6 changes: 6 additions & 0 deletions src/configurator/tokenPriceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export function tokenPriceService(opts?: TokenPriceServiceConfiguratorOpts): Pri
chainId: ChainId.Ethereum,
token: tokenStringToBuffer(ChainId.Ethereum, ZERO_EVM_ADDRESS),
},
// remap USDC@Linea price to USDC@Ethereum
'0x176211869cA2b568f2A7D4EE941E073a821EE1ff': {
type: 'redirect',
chainId: ChainId.Ethereum,
token: tokenStringToBuffer(ChainId.Ethereum, '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'),
},
},
[ChainId.Base]: {
// remap ETH@Base price to ETH@Ethereum
Expand Down
6 changes: 6 additions & 0 deletions src/hooks/HookEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,10 @@ export enum RejectionReason {
* indicates that non-finalized order is not covered by any custom block confirmation range
*/
NOT_YET_FINALIZED,

/**
* indicates that the order requires reserve token to be pre-swapped to the take token, but the operation can't be
* performed because swaps are not available on the take chain
*/
UNAVAILABLE_PRE_FULFILL_SWAP,
}
13 changes: 12 additions & 1 deletion src/processors/universal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
SwapConnectorRequest,
SwapConnectorResult
} from "@debridge-finance/dln-client/dist/types/swapConnector/swap.connector";
import { DexlessChains } from "../config";

// reasonable multiplier for gas estimated for the fulfill txn to define max
// gas we are willing to estimate
Expand Down Expand Up @@ -499,8 +500,18 @@ class UniversalProcessor extends BaseOrderProcessor {
return this.rejectOrder(metadata, message, RejectionReason.UNEXPECTED_GIVE_STATUS);
}

// perform rough estimation: assuming order.give.amount is what we need on balance
// reject orders that require pre-fulfill swaps on the dexless chains (e.g. Linea)
const pickedBucket = findExpectedBucket(orderInfo.order, context.config.buckets);
if (
DexlessChains[orderInfo.order.take.chainId]
&& !buffersAreEqual(pickedBucket.reserveDstToken, orderInfo.order.take.tokenAddress)
) {
const takeChainId = orderInfo.order.take.chainId;
const message = `swaps are unavailable on ${ChainId[takeChainId]}, can't perform pre-fulfill swap from ${tokenAddressToString(takeChainId, pickedBucket.reserveDstToken)} to ${tokenAddressToString(takeChainId, orderInfo.order.take.tokenAddress)}`;
return this.rejectOrder(metadata, message, RejectionReason.UNAVAILABLE_PRE_FULFILL_SWAP);
}

// perform rough estimation: assuming order.give.amount is what we need on balance
const [reserveSrcTokenDecimals, reserveDstTokenDecimals, takeTokenDecimals] = await Promise.all([
context.config.client.getDecimals(orderInfo.order.give.chainId, pickedBucket.reserveSrcToken, context.giveChain.fulfillProvider.connection as Web3),
context.config.client.getDecimals(orderInfo.order.take.chainId, pickedBucket.reserveDstToken, this.takeChain.fulfillProvider.connection as Web3),
Expand Down

0 comments on commit a676ad4

Please sign in to comment.