Skip to content

Commit ce19722

Browse files
committed
update router
1 parent 6a91a9c commit ce19722

File tree

2 files changed

+63
-31
lines changed

2 files changed

+63
-31
lines changed

docs/interacting.md

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,64 @@
11
# How to interact with different protocols using DeFi SDK contracts
22

33
!!! 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.
55

66
## 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.
109

1110
Overall, we highly recommend using our Transaction Builder [API](https://transactions.zerion.io/docs#/){target="_blank"}.
1211

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.
44+
It may be used for off-chain estimations.
45+
46+
## InteractiveAdapter interface
47+
1348
---
1449
```solidity
1550
deposit(TokenAmount[] tokenAmounts, bytes data) payable returns (address[])
1651
```
1752

1853
The function is used to deposit tokens to the protocol.
19-
`data` parameter is optional and usage is described in protocol's adapter NatSpec comments.
20-
Return values is a list of tokens returned by the adapter.
54+
`data` parameter is optional and usage is described in the protocol's adapter NatSpec comments.
55+
The return value is a list of tokens returned by the adapter.
2156

2257
---
2358
```solidity
2459
withdraw(TokenAmount[] tokenAmounts, bytes data) payable returns (address[])
2560
```
2661

2762
The function is used to withdraw tokens from the protocol.
28-
`data` parameter is optional and usage is described in protocol's adapter NatSpec comments.
29-
Return values is a list of tokens returned by the adapter.
63+
`data` parameter is optional and usage is described in the protocol's adapter NatSpec comments.
64+
The return value is a list of tokens returned by the adapter.

docs/reading.md

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
## Using AdapterRegistry contract with supported adapters
77

8-
The main contract for interaction is **AdapterRegistry**.
8+
The main contract for interaction is [AdapterRegistry](https://etherscan.io/address/0x06FE76B2f432fdfEcAEf1a7d4f6C3d41B5861672){target=_blank}.
99
It allows checking balances and exchange rates for tokens used in the different protocols.
1010

1111
Please, read the [Notes](#notes) before using this contract.
1212

13-
---
13+
---
1414
```solidity
1515
getBalances(address account) returns (ProtocolBalance[])
1616
```
@@ -24,7 +24,7 @@ Its exact definition may be found in [Structs.sol](https://github.com/zeriontech
2424

2525
This struct has protocol metadata as the first field.
2626
After that, adapter balances are added.
27-
The following object is an example of `ProtocolBalance` struct.
27+
The following object is an example of the `ProtocolBalance` struct.
2828

2929
```javascript
3030
{
@@ -79,16 +79,16 @@ The following object is an example of `ProtocolBalance` struct.
7979

8080
> NOTE! Filters out zero balances, adapters, and protocols without positive balances.
8181
82-
---
82+
---
8383
```solidity
8484
getProtocolBalances(address account, string[] protocolNames) returns (ProtocolBalance[])
8585
```
8686

87-
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.
8888

8989
> NOTE! Filters out zero balances, adapters, and protocols without positive balances.
9090
91-
---
91+
---
9292
```solidity
9393
getAdapterBalances(address account, address[] adapters) returns (AdapterBalance[])
9494
```
@@ -98,7 +98,7 @@ The function iterates only over the selected adapters.
9898

9999
> NOTE! Filters out zero balances and adapters without positive balances.
100100
101-
---
101+
---
102102
```solidity
103103
getAdapterBalance(address account, address adapter, address[] tokens) returns (AdapterBalance)
104104
```
@@ -109,64 +109,61 @@ The best option of getting the adapter address is calling `getProtocolAdapters('
109109

110110
> NOTE! Filters out zero balances.
111111
112-
---
112+
---
113113
```solidity
114114
getProtocolNames() returns (string[])
115115
```
116116

117117
The function returns the list of protocols supported by the **AdapterManager** contract.
118118

119-
---
119+
---
120120
```solidity
121121
getProtocolMetadata(string protocolName) returns (ProtocolMetadata)
122122
```
123123

124-
The function returns the protocol metadata, i.e. name, one line description, icon and website URL's, and version.
124+
The function returns the protocol metadata, i.e. name, one-line description, icon and website URLs, and version.
125125
This info may be upgraded by the `owner`.
126126
After any upgrade, the protocol version will be increased by 1.
127127

128-
---
128+
---
129129
```solidity
130130
getProtocolAdapters(string protocolName) returns (address[])
131131
```
132-
132+
133133
The function returns the list of protocol adapters for the given protocol name.
134134
After any upgrade, the protocol version will be increased by 1.
135135

136-
---
136+
---
137137
```solidity
138138
getSupportedTokens(address adapter) returns (address[])
139139
```
140-
141-
The function returns the list supported tokens for the given adapter address.
140+
141+
The function returns the list of supported tokens for the given adapter address.
142142
After any upgrade, the protocol version will be increased by 1.
143143

144-
---
144+
---
145145
```solidity
146146
getFullTokenBalance(string tokenType, address token) returns (FullTokenBalance)
147147
getFinalFullTokenBalance(string tokenType, address token) returns (FullTokenBalance)
148148
```
149149

150-
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.
151151
The first one will show the real underlying tokens (e.g. cDAI and cUSDC for Curve Compound pool).
152152
The second will try to recover the "deepest" underlying tokens (e.g. DAI and USDC for Curve Compound pool).
153153

154154
## Using AdapterRegistry contract with non-supported adapters
155155

156156
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).
158158

159159
More detailed information about adapters may be found in [adapters](supported-protocols/read-only-adapters.md) documentation.
160160

161161
## Notes
162162

163163
1. To check DSR balance, Maker **DSProxy**'s address should be used as `account` parameter.
164164

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.
166166

167167
3. If the balance is inaccessible, the registry will return 0 and, thus, will filter out the balance.
168168

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

Comments
 (0)