From e3d0704d4f1ea827a0b01c2448724e960ae63fe3 Mon Sep 17 00:00:00 2001 From: lash Date: Tue, 1 Aug 2023 16:07:31 +0100 Subject: [PATCH] Token swap interface implementation --- README.md | 43 ++++++++++++++++++---------------- doc/texinfo/overview.texi | 2 +- doc/texinfo/tokenswap.sol.texi | 15 ++++++++++++ python/README.md | 43 ++++++++++++++++++---------------- solidity/Minter.sol | 3 +++ solidity/TokenSwap.sol | 25 ++++++++++++++++++++ 6 files changed, 90 insertions(+), 41 deletions(-) create mode 100644 doc/texinfo/tokenswap.sol.texi create mode 100644 solidity/TokenSwap.sol diff --git a/README.md b/README.md index e37bb69..b15b463 100644 --- a/README.md +++ b/README.md @@ -471,6 +471,9 @@ Solidity interface definition // Tokens are successfully minted; by who, to whom and how much event Mint(address indexed _minter, address indexed _beneficiary, uint256 value); + // The given token has been successfully minted; by who, to whom and how much + event Mint(address indexed _minter, address indexed _beneficiary, address indexed _token, uint256 value); + // Mint the specified value of tokens to the specified recipient function mintTo(address _beneficiary, uint256 value) external returns (bool); @@ -628,33 +631,33 @@ Solidity interface definition Reference implementations - -### TokenVend +### TokenSwap -This interface defines the mechanism for which a specific ERC20 token -may be exchanged for a different ERC20 token. - -A typical use-case is generation of voting tokens based on a momentary -voucher balance. This is especially useful if the original ERC20 token -is subject to decay (demurrage). - -The tokens used for exchange **SHOULD** be locked for the full duration -of holding the vended tokens. - -The withdrawal function may or may not allow partial withdrawals. +Token swap interface that can fit token escrow aswell as token swap +contracts. ERC165 Interface identifier -8a13249c +9e2d0236 Solidity interface definition - interface ITokenVend { - // A new vended token has been created. - event TokenCreated(uint256 indexed _tokenIdx, uint256 indexed _supply, address _token); + interface ITokenSwap { + // Add inToken liquidity of the full balance of the sender + // Requires token approval for the balance. + function deposit(address _inToken) external returns (uint256); - // Create corresponding vended tokens for the control token balance of the caller. - function getFor(address _token) external returns (uint256); + // Add inToken liquidity to the tune of given value. + // Requires token approval for the corresponding value. + function deposit(address _inToken, uint256 _value) external returns (uint256); - // Recover control tokens that were used to retrieve the corresponding vended tokens. - function withdrawFor(address _token) external returns (uint256); + // Withdraw any pending outToken balance in the pool for the sender. + function withdraw(address _outToken) external returns (uint256); + + // Withdraw pending outToken balance of given value in the pool for the sender. + function withdraw(address _outToken, uint256 _value) external returns (uint256); + + // Exchange inToken equalling given value for outToken. + // Requires token approval for the value of inToken. + function withdraw(address _outToken, address _inToken, uint256 _value) external returns (uint256); } Reference implementations diff --git a/doc/texinfo/overview.texi b/doc/texinfo/overview.texi index 2706d17..b2c0604 100644 --- a/doc/texinfo/overview.texi +++ b/doc/texinfo/overview.texi @@ -76,7 +76,7 @@ The following well-known solidity interfaces are partially implemented in CIC na @include tokenratechange.sol.texi -@include tokenvend.sol.texi +@include tokenswap.sol.texi @include tokenvote.sol.texi diff --git a/doc/texinfo/tokenswap.sol.texi b/doc/texinfo/tokenswap.sol.texi new file mode 100644 index 0000000..c666e0d --- /dev/null +++ b/doc/texinfo/tokenswap.sol.texi @@ -0,0 +1,15 @@ +@subsection TokenSwap + +Token swap interface that can fit token escrow aswell as token swap contracts. + +@table @dfn +@item ERC165 Interface identifier +@include ../../build/TokenSwap.interface +@item Solidity interface definition +@include ../../build/contract_TokenSwap.texi +@item Reference implementations +@itemize +@item +@uref{git://holbrook.no/erc20-vend.git,} +@end itemize +@end table diff --git a/python/README.md b/python/README.md index e37bb69..b15b463 100644 --- a/python/README.md +++ b/python/README.md @@ -471,6 +471,9 @@ Solidity interface definition // Tokens are successfully minted; by who, to whom and how much event Mint(address indexed _minter, address indexed _beneficiary, uint256 value); + // The given token has been successfully minted; by who, to whom and how much + event Mint(address indexed _minter, address indexed _beneficiary, address indexed _token, uint256 value); + // Mint the specified value of tokens to the specified recipient function mintTo(address _beneficiary, uint256 value) external returns (bool); @@ -628,33 +631,33 @@ Solidity interface definition Reference implementations - -### TokenVend +### TokenSwap -This interface defines the mechanism for which a specific ERC20 token -may be exchanged for a different ERC20 token. - -A typical use-case is generation of voting tokens based on a momentary -voucher balance. This is especially useful if the original ERC20 token -is subject to decay (demurrage). - -The tokens used for exchange **SHOULD** be locked for the full duration -of holding the vended tokens. - -The withdrawal function may or may not allow partial withdrawals. +Token swap interface that can fit token escrow aswell as token swap +contracts. ERC165 Interface identifier -8a13249c +9e2d0236 Solidity interface definition - interface ITokenVend { - // A new vended token has been created. - event TokenCreated(uint256 indexed _tokenIdx, uint256 indexed _supply, address _token); + interface ITokenSwap { + // Add inToken liquidity of the full balance of the sender + // Requires token approval for the balance. + function deposit(address _inToken) external returns (uint256); - // Create corresponding vended tokens for the control token balance of the caller. - function getFor(address _token) external returns (uint256); + // Add inToken liquidity to the tune of given value. + // Requires token approval for the corresponding value. + function deposit(address _inToken, uint256 _value) external returns (uint256); - // Recover control tokens that were used to retrieve the corresponding vended tokens. - function withdrawFor(address _token) external returns (uint256); + // Withdraw any pending outToken balance in the pool for the sender. + function withdraw(address _outToken) external returns (uint256); + + // Withdraw pending outToken balance of given value in the pool for the sender. + function withdraw(address _outToken, uint256 _value) external returns (uint256); + + // Exchange inToken equalling given value for outToken. + // Requires token approval for the value of inToken. + function withdraw(address _outToken, address _inToken, uint256 _value) external returns (uint256); } Reference implementations diff --git a/solidity/Minter.sol b/solidity/Minter.sol index 5757a39..e0eeb64 100644 --- a/solidity/Minter.sol +++ b/solidity/Minter.sol @@ -8,6 +8,9 @@ interface IMinter { // Tokens are successfully minted; by who, to whom and how much event Mint(address indexed _minter, address indexed _beneficiary, uint256 value); + // The given token has been successfully minted; by who, to whom and how much + event Mint(address indexed _minter, address indexed _beneficiary, address indexed _token, uint256 value); + // Mint the specified value of tokens to the specified recipient function mintTo(address _beneficiary, uint256 value) external returns (bool); diff --git a/solidity/TokenSwap.sol b/solidity/TokenSwap.sol new file mode 100644 index 0000000..52d3641 --- /dev/null +++ b/solidity/TokenSwap.sol @@ -0,0 +1,25 @@ +pragma solidity >=0.6.12; + +// Author: Louis Holbrook 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 +// SPDX-License-Identifier: AGPL-3.0-or-later +// File-version: 1 + +interface ITokenSwap { + // Add inToken liquidity of the full balance of the sender + // Requires token approval for the balance. + function deposit(address _inToken) external returns (uint256); + + // Add inToken liquidity to the tune of given value. + // Requires token approval for the corresponding value. + function deposit(address _inToken, uint256 _value) external returns (uint256); + + // Withdraw any pending outToken balance in the pool for the sender. + function withdraw(address _outToken) external returns (uint256); + + // Withdraw pending outToken balance of given value in the pool for the sender. + function withdraw(address _outToken, uint256 _value) external returns (uint256); + + // Exchange inToken equalling given value for outToken. + // Requires token approval for the value of inToken. + function withdraw(address _outToken, address _inToken, uint256 _value) external returns (uint256); +}