-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement token interactions #16
Merged
Merged
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
74dd6fe
create and commit withPermit
HristiyanG 2053cd2
added withdraw based on payment method
HristiyanG e35b462
remove setPaymentReleased outside if block
HristiyanG 493847b
WIP Todos
thcrnk 77d06a3
added tests tkn tkn
HristiyanG 475b3c9
add EthPrice TokenDeposit flow
HristiyanG a6c41a4
added builder
HristiyanG 4ee23bb
added token price eth deposit
HristiyanG 4d8ca81
rename external functions
HristiyanG 8861b88
added dev comments
HristiyanG 757d26e
fixed older tests to call proper fn names
HristiyanG 1093070
removed commented lines
HristiyanG e8b02fb
accept only one voucher in withdraw fn
HristiyanG 2c7ac9d
added safe math on voucher creation, moved metadata notice above funcs
HristiyanG 0d9141a
missed safe math in require
HristiyanG 4946d52
temp commit
HristiyanG 7d6e5c8
added negative scenarios for tokenSupplyID and VoucherID creations
HristiyanG 39b5bfb
test refactoring
HristiyanG 9764e3a
resolved comments
HristiyanG 3758296
merged master
HristiyanG 667dc90
added comment why we need to explicitly cast address to payable in wi…
HristiyanG 43a9cd5
merged master
HristiyanG 44d3940
resolve comments and misspelled words
HristiyanG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ contract VoucherKernel is Ownable, usingHelpers { | |
//promise for an asset could be reusable, but simplified here for brevitbytes32 | ||
struct Promise { | ||
bytes32 promiseId; | ||
string assetTitle; //the asset that is offered | ||
uint256 nonce; //the asset that is offered | ||
thecryptofruit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
address seller; //the seller who created the promise | ||
|
||
//we simplify the value for the demoapp, otherwise voucher details would be packed in one bytes32 field value | ||
|
@@ -40,10 +40,19 @@ contract VoucherKernel is Ownable, usingHelpers { | |
|
||
uint idx; | ||
} | ||
|
||
struct VoucherPaymentMethod { | ||
uint8 paymentMethod; | ||
address addressTokenPrice; | ||
address addressTokenDeposits; | ||
} | ||
|
||
address public cashierAddress; //address of the Cashier contract | ||
|
||
mapping(bytes32 => Promise) public promises; //promises to deliver goods or services | ||
mapping(address => uint256) public tokenNonces; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment here why the Nonces are used |
||
mapping (uint256 => VoucherPaymentMethod) public paymentDetails; // tokenSupplyId to VoucherPaymentMethod | ||
|
||
bytes32[] public promiseKeys; | ||
|
||
mapping(address => uint256) public accountSupply; | ||
|
@@ -85,12 +94,20 @@ contract VoucherKernel is Ownable, usingHelpers { | |
|
||
event LogPromiseCreated( | ||
bytes32 indexed _promiseId, | ||
string indexed _assetTitle, | ||
uint256 indexed _nonce, | ||
address indexed _seller, | ||
uint256 _validFrom, | ||
uint256 _validTo, | ||
uint256 _idx | ||
); | ||
|
||
event LogVoucherDelivered( | ||
uint256 indexed _tokenIdSupply, | ||
uint256 _tokenIdVoucher, | ||
address _issuer, | ||
address _holder, | ||
bytes32 _promiseId | ||
); | ||
|
||
event LogVoucherRedeemed( | ||
uint256 _tokenIdVoucher, | ||
|
@@ -169,40 +186,39 @@ contract VoucherKernel is Ownable, usingHelpers { | |
* @notice Creating a new promise for goods or services. | ||
* Can be reused, e.g. for making different batches of these (but not in prototype). | ||
* @param _seller seller of the promise | ||
* @param _assetTitle Name of the asset | ||
* @param _validFrom Start of valid period | ||
* @param _validTo End of valid period | ||
* @param _price Price (payment amount) | ||
* @param _depositSe Seller's deposit | ||
* @param _depositBu Buyer's deposit | ||
*/ | ||
function createAssetPromise( | ||
function createTokenSupplyID( | ||
address _seller, | ||
string calldata _assetTitle, | ||
uint256 _validFrom, | ||
uint256 _validTo, | ||
uint256 _price, | ||
uint256 _depositSe, | ||
uint256 _depositBu | ||
uint256 _depositBu, | ||
uint256 _quantity | ||
) | ||
external | ||
onlyFromCashier | ||
returns (bytes32) | ||
returns (uint256) | ||
{ | ||
|
||
require(_validFrom <= _validTo, "INVALID_VALIDITY_FROM"); //hex"26" FISSION.code(FISSION.Category.Find, FISSION.Status.Above_Range_Overflow) | ||
require(_validTo >= block.timestamp, "INVALID_VALIDITY_TO"); //hex"24" FISSION.code(FISSION.Category.Find, FISSION.Status.BelowRange_Underflow) | ||
|
||
bytes32 key; | ||
key = keccak256(abi.encodePacked(_assetTitle, _validFrom, _validTo)); | ||
key = keccak256(abi.encodePacked(tokenNonces[_seller]++, _validFrom, _validTo)); | ||
|
||
if (promiseKeys.length > 0) { | ||
require(promiseKeys[promises[key].idx] != key, "PROMISE_ALREADY_EXISTS"); | ||
} | ||
|
||
promises[key] = Promise({ | ||
promiseId: key, | ||
assetTitle: _assetTitle, | ||
nonce: tokenNonces[_seller], | ||
seller: _seller, | ||
validFrom: _validFrom, | ||
validTo: _validTo, | ||
|
@@ -214,13 +230,30 @@ contract VoucherKernel is Ownable, usingHelpers { | |
|
||
promiseKeys.push(key); | ||
|
||
emit LogPromiseCreated(key, _assetTitle, msg.sender, _validFrom, _validTo, //_price, _depositSe, _depositBu, _complainPeriod, _cancelFaultPeriod, | ||
emit LogPromiseCreated(key, tokenNonces[_seller], _seller, _validFrom, _validTo, //_price, _depositSe, _depositBu, _complainPeriod, _cancelFaultPeriod, | ||
promiseKeys.length - 1); | ||
|
||
return key; | ||
} | ||
|
||
|
||
|
||
return createOrder(_seller, key, _quantity); | ||
} | ||
|
||
function createPaymentMethod( | ||
uint256 _tokenIdSupply, | ||
uint8 _paymentMethod, | ||
address _tokenPrice, | ||
address _tokenDeposits | ||
) | ||
external | ||
onlyFromCashier | ||
{ | ||
|
||
paymentDetails[_tokenIdSupply] = VoucherPaymentMethod({ | ||
paymentMethod: _paymentMethod, | ||
addressTokenPrice: _tokenPrice, | ||
addressTokenDeposits: _tokenDeposits | ||
|
||
}); | ||
} | ||
|
||
/** | ||
* @notice Create an order for offering a certain quantity of an asset | ||
* This creates a listing in a marketplace, technically as an ERC-1155 non-fungible token with supply. | ||
|
@@ -229,8 +262,7 @@ contract VoucherKernel is Ownable, usingHelpers { | |
* @param _quantity Quantity of assets on offer | ||
*/ | ||
function createOrder(address _seller, bytes32 _promiseId, uint256 _quantity) | ||
external | ||
onlyFromCashier | ||
private | ||
returns (uint256) | ||
{ | ||
require(_promiseId != bytes32(0), "UNSPECIFIED_PROMISE"); //hex"20" FISSION.code(FISSION.Category.Find, FISSION.Status.NotFound_Unequal_OutOfRange) | ||
|
@@ -256,13 +288,15 @@ contract VoucherKernel is Ownable, usingHelpers { | |
function fillOrder(uint256 _tokenIdSupply, address _issuer, address _holder) | ||
external | ||
onlyFromCashier | ||
returns (uint256) | ||
|
||
{ | ||
//checks | ||
checkOrderFillable(_tokenIdSupply, _issuer, _holder); | ||
|
||
//close order | ||
return extract721(_issuer, _holder, _tokenIdSupply); | ||
uint256 voucherTokenId = extract721(_issuer, _holder, _tokenIdSupply); | ||
|
||
emit LogVoucherDelivered(_tokenIdSupply, voucherTokenId, _issuer, _holder, getPromiseIdFromVoucherId(voucherTokenId)); | ||
} | ||
|
||
|
||
|
@@ -750,6 +784,20 @@ contract VoucherKernel is Ownable, usingHelpers { | |
bytes32 promiseKey = ordersPromise[_tokenIdSupply]; | ||
return (promises[promiseKey].price, promises[promiseKey].depositSe, promises[promiseKey].depositBu); | ||
} | ||
|
||
|
||
/** | ||
* @notice Get Buyer costs required to make an order for a supply token | ||
* @param _tokenIdSupply ID of the supply token | ||
* @return returns a tupple (Payment amount, Buyer's deposit) | ||
*/ | ||
function getBuyerOrderCosts(uint256 _tokenIdSupply) | ||
public view | ||
returns (uint256, uint256) | ||
{ | ||
bytes32 promiseKey = ordersPromise[_tokenIdSupply]; | ||
return (promises[promiseKey].price, promises[promiseKey].depositBu); | ||
} | ||
|
||
|
||
/** | ||
|
@@ -789,7 +837,38 @@ contract VoucherKernel is Ownable, usingHelpers { | |
{ | ||
return tokensContract.ownerOf(_tokenIdVoucher); | ||
} | ||
|
||
|
||
|
||
/** | ||
* @notice Get the address of the token where the price for the supply is held | ||
* @param _tokenIdSupply ID of the voucher token | ||
* @return Address of the token | ||
*/ | ||
function getVoucherPriceToken(uint256 _tokenIdSupply) | ||
public view | ||
returns (address) | ||
{ | ||
return paymentDetails[_tokenIdSupply].addressTokenPrice; | ||
} | ||
|
||
/** | ||
* @notice Get the address of the token where the deposits for the supply are held | ||
* @param _tokenIdSupply ID of the voucher token | ||
* @return Address of the token | ||
*/ | ||
function getVoucherDepositToken(uint256 _tokenIdSupply) | ||
public view | ||
returns (address) | ||
{ | ||
return paymentDetails[_tokenIdSupply].addressTokenDeposits; | ||
} | ||
|
||
function getVoucherPaymentMethod(uint256 _tokenIdSupply) | ||
public view | ||
returns (uint8) | ||
{ | ||
return paymentDetails[_tokenIdSupply].paymentMethod; | ||
} | ||
|
||
/** | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry probably we had some misunderstanding on the previous PR. I think it would be helpful if we have the comment here, how this permit hash is constructed, otherwise it just looks like magic.