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

Commit

Permalink
feat: use Oneinch v5 and common CrosschainForwarder (#172)
Browse files Browse the repository at this point in the history
* feat: use Oneinch v5 and common CrosschainForwarder

* config improved + docs

---------

Co-authored-by: Alexey Churkin <[email protected]>
  • Loading branch information
mncdg and alexeychr authored Feb 9, 2024
1 parent b7b60a9 commit a653d55
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 115 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [How `dln-taker` works?](#how-dln-taker-works)
- [Installation](#installation)
- [Preparing the environment](#preparing-the-environment)
- [Obtaining an API token for 1inch.io API](#obtaining-an-api-token-for-1inchio-api)
- [Understanding reserve funds](#understanding-reserve-funds)
- [Deploying reserve funds](#deploying-reserve-funds)
- [Managing cross-chain risk/reward ratio](#managing-cross-chain-riskreward-ratio)
Expand Down Expand Up @@ -108,6 +109,17 @@ The next step is to deploy your assets to the addresses used by `dln-taker` for

If you wish to avoid order fulfillments in a particular chain, use the [`disableFulfill`](./ADVANCED.md#disablefulfill) filter in the config file, however you are **still required** to fill the variables with correct values to enable orders coming from such chain. For example, if you wouldn't want to deploy liquidity on Solana (and thus avoid fulfillments in this chain), add the `disableFulfill` filter to the Solana's section of the configuration file, but you'll still be able to fulfill orders coming **from** Solana. If you wish to exclude the chain from processing, skipping orders coming from and to such chain, just comment out the corresponding section in the config file: in this case, any order coming from or to Solana would be dropped by your instance of `dln-taker`.

### Obtaining an API token for 1inch.io API

Starting v3.3.0, dln-taker uses 1inch's API v5, which requires a valid API token. Before launching the script, you need to obtain one at https://portal.1inch.dev, and set it in the `.env` file to the `ONEINCH_API_V5_TOKEN` environment variable. Ensure that this variable is correctly passed in the configuration file:

```ts
oneInchConfig: {
apiToken: `${process.env.ONEINCH_API_V5_TOKEN}`,
disablePMMProtocols: true,
disabledProtocols: [],
},
```

### Understanding reserve funds

Expand Down
306 changes: 227 additions & 79 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@debridge-finance/dln-taker",
"version": "3.2.5",
"version": "3.3.0",
"description": "DLN executor is the rule-based daemon service developed to automatically execute orders placed on the deSwap Liquidity Network (DLN) across supported blockchains",
"license": "GPL-3.0-only",
"author": "deBridge",
Expand Down Expand Up @@ -33,7 +33,7 @@
},
"types": "./dist/index.d.ts",
"dependencies": {
"@debridge-finance/dln-client": "8.3.3",
"@debridge-finance/dln-client": "8.3.5",
"@debridge-finance/legacy-dln-profitability": "3.2.0",
"@debridge-finance/solana-utils": "4.2.1",
"@protobuf-ts/plugin": "2.8.1",
Expand Down
7 changes: 7 additions & 0 deletions sample.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ const config: ExecutorLaunchConfig = {
maxAccounts: 16,
},

oneInchConfig: {
// MANDATORY
apiToken: `${process.env.ONEINCH_API_V5_TOKEN}`, // obtain one at https://portal.1inch.dev
disablePMMProtocols: true,
disabledProtocols: [],
},

buckets: [
//
// Setting the USDC bucket (all tokens are emitted by Circle Inc on every DLN supported chain)
Expand Down
3 changes: 3 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ COINGECKO_API_KEY=
# a key to Sentry to enable logging. May be left blank, for advanced setups only.
SENTRY_DSN=

# Mandatory 1inch API token (obtain at https://portal.1inch.dev)
ONEINCH_API_V5_TOKEN=

##
## Per-chain secrets
##
Expand Down
7 changes: 7 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,11 @@ export interface ExecutorLaunchConfig {
maxAccounts?: number;
blacklistedDexes?: Array<string>;
};

oneInchConfig: {
apiToken: string;
apiServer?: string;
disablePMMProtocols?: boolean;
disabledProtocols?: string[];
};
}
21 changes: 1 addition & 20 deletions src/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const PRODUCTION: Env = {
pmmSrc: '0xeF4fB24aD0916217251F553c0596F8Edc630EB66',
pmmDst: '0xE7351Fd770A37282b91D153Ee690B63579D6dd7f',
evm: {
forwarderContract: '0xc31fc94F3Fd088eE53ac915D6e8a14fF25a23C47',
forwarderContract: '0x663DC15D3C1aC63ff12E45Ab68FeA3F0a883C251',
},
},
chains: {
Expand All @@ -107,25 +107,6 @@ const PRODUCTION: Env = {
deBridgeContract: '0xc1656B63D9EEBa6d114f6bE19565177893e5bCBF',
pmmSrc: '0xeF4fB24aD0916217251F553c0596F8Edc630EB66',
pmmDst: '0xE7351Fd770A37282b91D153Ee690B63579D6dd7f',
evm: {
forwarderContract: '0x663DC15D3C1aC63ff12E45Ab68FeA3F0a883C251',
},
},
[ChainId.Optimism]: {
deBridgeContract: '0x43dE2d77BF8027e25dBD179B491e8d64f38398aA',
pmmSrc: '0xeF4fB24aD0916217251F553c0596F8Edc630EB66',
pmmDst: '0xE7351Fd770A37282b91D153Ee690B63579D6dd7f',
evm: {
forwarderContract: '0x663DC15D3C1aC63ff12E45Ab68FeA3F0a883C251',
},
},
[ChainId.Linea]: {
deBridgeContract: '0x43dE2d77BF8027e25dBD179B491e8d64f38398aA',
pmmSrc: '0xeF4fB24aD0916217251F553c0596F8Edc630EB66',
pmmDst: '0xE7351Fd770A37282b91D153Ee690B63579D6dd7f',
evm: {
forwarderContract: '0x663DC15D3C1aC63ff12E45Ab68FeA3F0a883C251',
},
},
},
};
Expand Down
4 changes: 1 addition & 3 deletions src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ export class Executor implements IExecutor {

#isInitialized = false;

readonly #url1Inch = 'https://nodes.debridge.finance';

private readonly logger: Logger;

constructor(logger: Logger) {
Expand Down Expand Up @@ -256,7 +254,7 @@ export class Executor implements IExecutor {
this.subsidizationRules = config.subsidizationRules || [];

this.swapConnector = new SwapConnectorImplementationService({
oneInchApi: this.#url1Inch,
oneInchConfig: config.oneInchConfig,
});

this.buckets = Executor.getTokenBuckets(config.buckets);
Expand Down
33 changes: 22 additions & 11 deletions src/processors/swap-connector-implementation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,41 @@ import {
SwapConnectorResult,
} from '@debridge-finance/dln-client';

type OneInchConfig = {
apiToken?: string;
apiServer?: string;
disablePMMProtocols?: boolean;
disabledProtocols?: string[];
};

export class SwapConnectorImplementationService implements SwapConnector {
readonly #connectors: { [key in ChainId]: SwapConnector | null };

constructor(config: { oneInchApi: string }) {
const oneInchV4Connector = new OneInch.OneInchV4Connector(config.oneInchApi);
const oneInchV5Connector = new OneInch.OneInchV5Connector(config.oneInchApi);
constructor(configuration?: { oneInchConfig?: OneInchConfig }) {
const oneInchV5Connector = new OneInch.OneInchV5Connector({
customApiURL: configuration?.oneInchConfig?.apiServer || 'https://api.1inch.dev/swap',
token: configuration?.oneInchConfig?.apiToken,
disablePMMProtocols: configuration?.oneInchConfig?.disablePMMProtocols,
disabledProtocols: configuration?.oneInchConfig?.disabledProtocols,
});

this.#connectors = {
[ChainId.Arbitrum]: oneInchV4Connector,
[ChainId.Arbitrum]: oneInchV5Connector,
[ChainId.ArbitrumTest]: null,
[ChainId.Avalanche]: oneInchV4Connector,
[ChainId.Avalanche]: oneInchV5Connector,
[ChainId.AvalancheTest]: null,
[ChainId.Base]: oneInchV5Connector,
[ChainId.BSC]: oneInchV4Connector,
[ChainId.BSC]: oneInchV5Connector,
[ChainId.BSCTest]: null,
[ChainId.Ethereum]: oneInchV4Connector,
[ChainId.Fantom]: oneInchV4Connector,
[ChainId.Ethereum]: oneInchV5Connector,
[ChainId.Fantom]: oneInchV5Connector,
[ChainId.Heco]: null,
[ChainId.HecoTest]: null,
[ChainId.Kovan]: null,
[ChainId.Linea]: oneInchV4Connector,
[ChainId.Linea]: oneInchV5Connector,
[ChainId.Neon]: null,
[ChainId.Optimism]: oneInchV4Connector,
[ChainId.Polygon]: oneInchV4Connector,
[ChainId.Optimism]: oneInchV5Connector,
[ChainId.Polygon]: oneInchV5Connector,
[ChainId.PolygonTest]: null,
[ChainId.Solana]: null,
};
Expand Down

0 comments on commit a653d55

Please sign in to comment.