From b9a29b7827fd28fb764049b099ef1269473a5fc5 Mon Sep 17 00:00:00 2001 From: lash Date: Thu, 3 Aug 2023 14:13:26 +0100 Subject: [PATCH] Add tokenquote interface --- README.md | 28 +++++++++++++++++++++++++++- doc/texinfo/overview.texi | 2 ++ doc/texinfo/tokenlimit.sol.texi | 2 +- doc/texinfo/tokenquote.sol.texi | 20 ++++++++++++++++++++ python/README.md | 28 +++++++++++++++++++++++++++- solidity/TokenLimit.sol | 3 +++ solidity/TokenQuote.sol | 13 +++++++++++++ 7 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 doc/texinfo/tokenquote.sol.texi create mode 100644 solidity/TokenQuote.sol diff --git a/README.md b/README.md index 0d2b702..6def7fe 100644 --- a/README.md +++ b/README.md @@ -638,7 +638,7 @@ Define limits of value amounts of tokens that individual addresses can hold. Limits are inclusive; a limit for 42 means transfer resulting in a token -balance \_higher\_ than 42 should be rejected. +balance *higher* than 42 should be rejected. A return value of 0 indicates that the token is categorically not accepted by the holder. @@ -650,6 +650,9 @@ accepted by the holder. #### Solidity interface definition interface ITokenLimit { + // Returns limit of total value a holder will accept of a specific token. + // The value limit returned is inclusive; A limit of 42 means any operation resulting in a balance OVER 42 should be rejected. + // A value of 0 means that no value of the token is accepted. function limitOf(address _token, address _holder) external view returns(uint256); } @@ -657,6 +660,29 @@ accepted by the holder. - +### TokenQuote + +Quote an output token value for a given value of input tokens. + +Both input and output value is denominated in the smallest available +unit of respective tokens. + +#### ERC165 Interface identifier + +dbb21d40 + +#### Solidity interface definition + + interface ITokenQuote { + // Returns, within a current context, what value of outTokens the given value of inTokens translates to. + // The values are given in smallest unit of each respective token. + function valueFor(address _outToken, address _inToken, uint256 value) external view returns (uint256); + } + +#### Example implementation + +- + ### TokenRateChange Enables detection of properties for CIC tokens that change value over diff --git a/doc/texinfo/overview.texi b/doc/texinfo/overview.texi index 846375a..8751c43 100644 --- a/doc/texinfo/overview.texi +++ b/doc/texinfo/overview.texi @@ -76,6 +76,8 @@ The following well-known solidity interfaces are partially implemented in CIC na @include tokenlimit.sol.texi +@include tokenquote.sol.texi + @include tokenratechange.sol.texi @include tokenswap.sol.texi diff --git a/doc/texinfo/tokenlimit.sol.texi b/doc/texinfo/tokenlimit.sol.texi index a63bc42..0a8f6c1 100644 --- a/doc/texinfo/tokenlimit.sol.texi +++ b/doc/texinfo/tokenlimit.sol.texi @@ -2,7 +2,7 @@ Define limits of value amounts of tokens that individual addresses can hold. -Limits are inclusive; a limit for 42 means transfer resulting in a token balance _higher_ than 42 should be rejected. +Limits are inclusive; a limit for 42 means transfer resulting in a token balance @emph{higher} than 42 should be rejected. A return value of 0 indicates that the token is categorically not accepted by the holder. diff --git a/doc/texinfo/tokenquote.sol.texi b/doc/texinfo/tokenquote.sol.texi new file mode 100644 index 0000000..a8d5d49 --- /dev/null +++ b/doc/texinfo/tokenquote.sol.texi @@ -0,0 +1,20 @@ +@subsection TokenQuote + +Quote an output token value for a given value of input tokens. + +Both input and output value is denominated in the smallest available unit of respective tokens. + +@subsubsection ERC165 Interface identifier + +@include ../../build/TokenQuote.interface + +@subsubsection Solidity interface definition + +@include ../../build/contract_TokenQuote.texi + +@subsubsection Example implementation + +@itemize +@item +@uref{git://holbrook.no/erc20-limiter.git,} +@end itemize diff --git a/python/README.md b/python/README.md index 0d2b702..6def7fe 100644 --- a/python/README.md +++ b/python/README.md @@ -638,7 +638,7 @@ Define limits of value amounts of tokens that individual addresses can hold. Limits are inclusive; a limit for 42 means transfer resulting in a token -balance \_higher\_ than 42 should be rejected. +balance *higher* than 42 should be rejected. A return value of 0 indicates that the token is categorically not accepted by the holder. @@ -650,6 +650,9 @@ accepted by the holder. #### Solidity interface definition interface ITokenLimit { + // Returns limit of total value a holder will accept of a specific token. + // The value limit returned is inclusive; A limit of 42 means any operation resulting in a balance OVER 42 should be rejected. + // A value of 0 means that no value of the token is accepted. function limitOf(address _token, address _holder) external view returns(uint256); } @@ -657,6 +660,29 @@ accepted by the holder. - +### TokenQuote + +Quote an output token value for a given value of input tokens. + +Both input and output value is denominated in the smallest available +unit of respective tokens. + +#### ERC165 Interface identifier + +dbb21d40 + +#### Solidity interface definition + + interface ITokenQuote { + // Returns, within a current context, what value of outTokens the given value of inTokens translates to. + // The values are given in smallest unit of each respective token. + function valueFor(address _outToken, address _inToken, uint256 value) external view returns (uint256); + } + +#### Example implementation + +- + ### TokenRateChange Enables detection of properties for CIC tokens that change value over diff --git a/solidity/TokenLimit.sol b/solidity/TokenLimit.sol index 32a8083..4c58ffe 100644 --- a/solidity/TokenLimit.sol +++ b/solidity/TokenLimit.sol @@ -5,5 +5,8 @@ pragma solidity >=0.6.12; // File-version: 1 interface ITokenLimit { + // Returns limit of total value a holder will accept of a specific token. + // The value limit returned is inclusive; A limit of 42 means any operation resulting in a balance OVER 42 should be rejected. + // A value of 0 means that no value of the token is accepted. function limitOf(address _token, address _holder) external view returns(uint256); } diff --git a/solidity/TokenQuote.sol b/solidity/TokenQuote.sol new file mode 100644 index 0000000..2623af5 --- /dev/null +++ b/solidity/TokenQuote.sol @@ -0,0 +1,13 @@ +pragma solidity >=0.6.12; + +// Author: Louis Holbrook 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 +// SPDX-License-Identifier: AGPL-3.0-or-later +// File-version: 1 + +// Value translator between tokens + +interface ITokenQuote { + // Returns, within a current context, what value of outTokens the given value of inTokens translates to. + // The values are given in smallest unit of each respective token. + function valueFor(address _outToken, address _inToken, uint256 value) external view returns (uint256); +}