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

Commit a653d55

Browse files
mncdgalexeychr
andauthored
feat: use Oneinch v5 and common CrosschainForwarder (#172)
* feat: use Oneinch v5 and common CrosschainForwarder * config improved + docs --------- Co-authored-by: Alexey Churkin <[email protected]>
1 parent b7b60a9 commit a653d55

File tree

9 files changed

+282
-115
lines changed

9 files changed

+282
-115
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [How `dln-taker` works?](#how-dln-taker-works)
1010
- [Installation](#installation)
1111
- [Preparing the environment](#preparing-the-environment)
12+
- [Obtaining an API token for 1inch.io API](#obtaining-an-api-token-for-1inchio-api)
1213
- [Understanding reserve funds](#understanding-reserve-funds)
1314
- [Deploying reserve funds](#deploying-reserve-funds)
1415
- [Managing cross-chain risk/reward ratio](#managing-cross-chain-riskreward-ratio)
@@ -108,6 +109,17 @@ The next step is to deploy your assets to the addresses used by `dln-taker` for
108109

109110
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`.
110111

112+
### Obtaining an API token for 1inch.io API
113+
114+
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:
115+
116+
```ts
117+
oneInchConfig: {
118+
apiToken: `${process.env.ONEINCH_API_V5_TOKEN}`,
119+
disablePMMProtocols: true,
120+
disabledProtocols: [],
121+
},
122+
```
111123

112124
### Understanding reserve funds
113125

package-lock.json

Lines changed: 227 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@debridge-finance/dln-taker",
3-
"version": "3.2.5",
3+
"version": "3.3.0",
44
"description": "DLN executor is the rule-based daemon service developed to automatically execute orders placed on the deSwap Liquidity Network (DLN) across supported blockchains",
55
"license": "GPL-3.0-only",
66
"author": "deBridge",
@@ -33,7 +33,7 @@
3333
},
3434
"types": "./dist/index.d.ts",
3535
"dependencies": {
36-
"@debridge-finance/dln-client": "8.3.3",
36+
"@debridge-finance/dln-client": "8.3.5",
3737
"@debridge-finance/legacy-dln-profitability": "3.2.0",
3838
"@debridge-finance/solana-utils": "4.2.1",
3939
"@protobuf-ts/plugin": "2.8.1",

sample.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ const config: ExecutorLaunchConfig = {
2020
maxAccounts: 16,
2121
},
2222

23+
oneInchConfig: {
24+
// MANDATORY
25+
apiToken: `${process.env.ONEINCH_API_V5_TOKEN}`, // obtain one at https://portal.1inch.dev
26+
disablePMMProtocols: true,
27+
disabledProtocols: [],
28+
},
29+
2330
buckets: [
2431
//
2532
// Setting the USDC bucket (all tokens are emitted by Circle Inc on every DLN supported chain)

sample.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ COINGECKO_API_KEY=
1818
# a key to Sentry to enable logging. May be left blank, for advanced setups only.
1919
SENTRY_DSN=
2020

21+
# Mandatory 1inch API token (obtain at https://portal.1inch.dev)
22+
ONEINCH_API_V5_TOKEN=
23+
2124
##
2225
## Per-chain secrets
2326
##

src/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,11 @@ export interface ExecutorLaunchConfig {
342342
maxAccounts?: number;
343343
blacklistedDexes?: Array<string>;
344344
};
345+
346+
oneInchConfig: {
347+
apiToken: string;
348+
apiServer?: string;
349+
disablePMMProtocols?: boolean;
350+
disabledProtocols?: string[];
351+
};
345352
}

src/environments.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const PRODUCTION: Env = {
9191
pmmSrc: '0xeF4fB24aD0916217251F553c0596F8Edc630EB66',
9292
pmmDst: '0xE7351Fd770A37282b91D153Ee690B63579D6dd7f',
9393
evm: {
94-
forwarderContract: '0xc31fc94F3Fd088eE53ac915D6e8a14fF25a23C47',
94+
forwarderContract: '0x663DC15D3C1aC63ff12E45Ab68FeA3F0a883C251',
9595
},
9696
},
9797
chains: {
@@ -107,25 +107,6 @@ const PRODUCTION: Env = {
107107
deBridgeContract: '0xc1656B63D9EEBa6d114f6bE19565177893e5bCBF',
108108
pmmSrc: '0xeF4fB24aD0916217251F553c0596F8Edc630EB66',
109109
pmmDst: '0xE7351Fd770A37282b91D153Ee690B63579D6dd7f',
110-
evm: {
111-
forwarderContract: '0x663DC15D3C1aC63ff12E45Ab68FeA3F0a883C251',
112-
},
113-
},
114-
[ChainId.Optimism]: {
115-
deBridgeContract: '0x43dE2d77BF8027e25dBD179B491e8d64f38398aA',
116-
pmmSrc: '0xeF4fB24aD0916217251F553c0596F8Edc630EB66',
117-
pmmDst: '0xE7351Fd770A37282b91D153Ee690B63579D6dd7f',
118-
evm: {
119-
forwarderContract: '0x663DC15D3C1aC63ff12E45Ab68FeA3F0a883C251',
120-
},
121-
},
122-
[ChainId.Linea]: {
123-
deBridgeContract: '0x43dE2d77BF8027e25dBD179B491e8d64f38398aA',
124-
pmmSrc: '0xeF4fB24aD0916217251F553c0596F8Edc630EB66',
125-
pmmDst: '0xE7351Fd770A37282b91D153Ee690B63579D6dd7f',
126-
evm: {
127-
forwarderContract: '0x663DC15D3C1aC63ff12E45Ab68FeA3F0a883C251',
128-
},
129110
},
130111
},
131112
};

src/executor.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ export class Executor implements IExecutor {
174174

175175
#isInitialized = false;
176176

177-
readonly #url1Inch = 'https://nodes.debridge.finance';
178-
179177
private readonly logger: Logger;
180178

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

258256
this.swapConnector = new SwapConnectorImplementationService({
259-
oneInchApi: this.#url1Inch,
257+
oneInchConfig: config.oneInchConfig,
260258
});
261259

262260
this.buckets = Executor.getTokenBuckets(config.buckets);

src/processors/swap-connector-implementation.service.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,41 @@ import {
99
SwapConnectorResult,
1010
} from '@debridge-finance/dln-client';
1111

12+
type OneInchConfig = {
13+
apiToken?: string;
14+
apiServer?: string;
15+
disablePMMProtocols?: boolean;
16+
disabledProtocols?: string[];
17+
};
18+
1219
export class SwapConnectorImplementationService implements SwapConnector {
1320
readonly #connectors: { [key in ChainId]: SwapConnector | null };
1421

15-
constructor(config: { oneInchApi: string }) {
16-
const oneInchV4Connector = new OneInch.OneInchV4Connector(config.oneInchApi);
17-
const oneInchV5Connector = new OneInch.OneInchV5Connector(config.oneInchApi);
22+
constructor(configuration?: { oneInchConfig?: OneInchConfig }) {
23+
const oneInchV5Connector = new OneInch.OneInchV5Connector({
24+
customApiURL: configuration?.oneInchConfig?.apiServer || 'https://api.1inch.dev/swap',
25+
token: configuration?.oneInchConfig?.apiToken,
26+
disablePMMProtocols: configuration?.oneInchConfig?.disablePMMProtocols,
27+
disabledProtocols: configuration?.oneInchConfig?.disabledProtocols,
28+
});
1829

1930
this.#connectors = {
20-
[ChainId.Arbitrum]: oneInchV4Connector,
31+
[ChainId.Arbitrum]: oneInchV5Connector,
2132
[ChainId.ArbitrumTest]: null,
22-
[ChainId.Avalanche]: oneInchV4Connector,
33+
[ChainId.Avalanche]: oneInchV5Connector,
2334
[ChainId.AvalancheTest]: null,
2435
[ChainId.Base]: oneInchV5Connector,
25-
[ChainId.BSC]: oneInchV4Connector,
36+
[ChainId.BSC]: oneInchV5Connector,
2637
[ChainId.BSCTest]: null,
27-
[ChainId.Ethereum]: oneInchV4Connector,
28-
[ChainId.Fantom]: oneInchV4Connector,
38+
[ChainId.Ethereum]: oneInchV5Connector,
39+
[ChainId.Fantom]: oneInchV5Connector,
2940
[ChainId.Heco]: null,
3041
[ChainId.HecoTest]: null,
3142
[ChainId.Kovan]: null,
32-
[ChainId.Linea]: oneInchV4Connector,
43+
[ChainId.Linea]: oneInchV5Connector,
3344
[ChainId.Neon]: null,
34-
[ChainId.Optimism]: oneInchV4Connector,
35-
[ChainId.Polygon]: oneInchV4Connector,
45+
[ChainId.Optimism]: oneInchV5Connector,
46+
[ChainId.Polygon]: oneInchV5Connector,
3647
[ChainId.PolygonTest]: null,
3748
[ChainId.Solana]: null,
3849
};

0 commit comments

Comments
 (0)