You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# How to interact with different protocols using DeFi SDK contracts
2
2
3
3
!!! note ""
4
-
Interactive adapters are maintained in [`interactive-updates`](https://github.com/zeriontech/defi-sdk/tree/interactive-updates){target="_blank"} branch of defi-sdk repo.
4
+
Interactive adapters are maintained in [`interactive`](https://github.com/zeriontech/defi-sdk/tree/interactive-updates){target="_blank"} branch of defi-sdk repo.
5
5
6
6
## Using InteractiveAdapter for interaction with different protocols
7
-
8
-
Using interactive adapters is not encouraged.
9
-
Interactive adapters should be used via interaction with the [Router](https://etherscan.io/address/0xB2BE281e8b11b47FeC825973fc8BB95332022A54){target=_blank} contract as it implements the required security checks.
7
+
The main contract for interaction is [Router](https://etherscan.io/address/0xB2BE281e8b11b47FeC825973fc8BB95332022A54){target=_blank}.
8
+
Using interactive adapters directly is not encouraged as **Router** contract implements the required security checks.
10
9
11
10
Overall, we highly recommend using our Transaction Builder [API](https://transactions.zerion.io/docs#/){target="_blank"}.
12
11
12
+
## Router interface
13
+
14
+
---
15
+
```solidity
16
+
function startExecution(
17
+
Action[] actions,
18
+
TokenAmount[] inputs,
19
+
Fee fee,
20
+
AbsoluteTokenAmount[] requiredOutputs
21
+
) returns (AbsoluteTokenAmount[] actualOutputs)
22
+
```
23
+
This is the main function for interaction with the **Router** contract.
24
+
25
+
The list of actions describes the sequence of operations (like swap, deposit, etc.) made in a single transaction.
26
+
Every action consists of the following elements:
27
+
- interactive adapter name
28
+
- action type, whether to call `deposit()` or `withdraw()` function of the adapter
29
+
- amounts of tokens that should be used in this action
30
+
- additional `data` parameter, which depends on the adapter implementation
31
+
32
+
The last two elements of action are passed to the proper function as parameters.
33
+
34
+
The list of inputs describes the input tokens that should be transferred from the caller account.
35
+
Note, that enough amounts of tokens should be previously approved for the **Router** contract.
36
+
37
+
The fee parameter is responsible for charging additional fees from the input amount.
38
+
However, its usage is discouraged as it significantly raises the network fee.
39
+
40
+
The last parameter is the list of output tokens with the amount requirements.
41
+
In case the requirement is not fulfilled, the transaction reverts.
42
+
43
+
The return value is a list of actual output amounts.
The function works exactly as `getBalances()`, but iterates only over the selected protocols. `protocolNames` consists of protocol names that are listed in [Supported protocols](#supported-protocols) section.
87
+
The function works exactly as `getBalances()`, but iterates only over the selected protocols. `protocolNames` consists of protocol names that are listed in the [Supported protocols](#supported-protocols) section.
88
88
89
89
> NOTE! Filters out zero balances, adapters, and protocols without positive balances.
Both functions returns the representation of the token's full share (1e18) in the underlying tokens.
150
+
Both functions return the representation of the token's full share (1e18) in the underlying tokens.
151
151
The first one will show the real underlying tokens (e.g. cDAI and cUSDC for Curve Compound pool).
152
152
The second will try to recover the "deepest" underlying tokens (e.g. DAI and USDC for Curve Compound pool).
153
153
154
154
## Using AdapterRegistry contract with non-supported adapters
155
155
156
156
In case adapter or asset is not supported by **AdapterManager** contract, functions with adapters (and assets) being function's arguments may be used (e.g. `getAdapterBalances()` function).
157
-
In this case, one should be sure that token type used in the adapter is supported by the registry (or use "ERC20" token type instead).
157
+
In this case, one should be sure that the token type used in the adapter is supported by the registry (or use "ERC20" token type instead).
158
158
159
159
More detailed information about adapters may be found in [adapters](supported-protocols/read-only-adapters.md) documentation.
160
160
161
161
## Notes
162
162
163
163
1. To check DSR balance, Maker **DSProxy**'s address should be used as `account` parameter.
164
164
165
-
2. Zero balances are filtered out, adapter balances and protocols without positive balances are filtered out, too.
165
+
2. Zero balances are filtered out. Adapter balances and protocols without positive balances are filtered out, too.
166
166
167
167
3. If the balance is inaccessible, the registry will return 0 and, thus, will filter out the balance.
168
168
169
-
4. If the token's metadata is inaccessible, the **AdapterRegistry** contract will return
170
-
- "Not available" as token name,
171
-
- "N/A" as token symbol,
172
-
- 0 as token decimals.
169
+
4. If the token's metadata is inaccessible, the **AdapterRegistry** contract will return `"Not available"` as token name, `"N/A"` as a token symbol, and `0` as token decimals.
0 commit comments