This repository has been archived by the owner on Aug 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* swap: correct price handling and reset balances * swap: conversion to wei on cheque creation; cleanup * swap: bug fixes and TestEmitCheque * swap: addressed PR comments * swap: minor fixes due to PR comments
- Loading branch information
1 parent
bb6566f
commit 579cebb
Showing
14 changed files
with
583 additions
and
256 deletions.
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
This file was deleted.
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 |
---|---|---|
@@ -1,7 +1,40 @@ | ||
// Copyright 2019 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package swap | ||
|
||
// Uknown for now, placeholder values | ||
import "time" | ||
|
||
// These are currently arbitrary values which have not been verified nor tested | ||
// Need experimentation to arrive to values which make sense | ||
const ( | ||
// Thresholds which trigger payment or disconnection. The unit is in honey (internal accounting unit) | ||
DefaultPaymentThreshold = 1000000 | ||
DefaultDisconnectThreshold = 1500000 | ||
// DefaultInitialDepositAmount is the default amount to send to the contract when initially deploying | ||
// TODO: deliberate value for now; needs experimentation | ||
DefaultInitialDepositAmount = 0 | ||
|
||
deployRetries = 5 | ||
// delay between retries | ||
deployDelay = 1 * time.Second | ||
// Default timeout until cashing in cheques is possible - TODO: deliberate value, experiment | ||
// Should be non-zero once we implement waivers | ||
defaultCashInDelay = uint64(0) | ||
// This is the amount of time in seconds which an issuer has to wait to decrease the harddeposit of a beneficiary. | ||
// The smart-contract allows for setting this variable differently per beneficiary | ||
defaultHarddepositTimeoutDuration = 24 * time.Hour | ||
) |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2019 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package swap | ||
|
||
// PriceOracle is the interface through which Oracles will deliver prices | ||
type PriceOracle interface { | ||
GetPrice(honey uint64) (uint64, error) | ||
} | ||
|
||
// NewPriceOracle returns the actual oracle to be used for discovering the price | ||
// TODO: Add a config flag so that this can be configured via command line | ||
// For now it will return a default one | ||
func NewPriceOracle() PriceOracle { | ||
cpo := &FixedPriceOracle{ | ||
honeyPrice: defaultHoneyPrice, | ||
} | ||
return cpo | ||
} | ||
|
||
// FixedPriceOracle is a price oracle which which returns a fixed price. | ||
// It is the default price oracle used as a placeholder for this iteration of the implementation. | ||
// In production this should probably be some on-chain oracle called remotely | ||
type FixedPriceOracle struct { | ||
honeyPrice uint64 | ||
} | ||
|
||
// GetPrice returns the actual price for honey | ||
func (cpo *FixedPriceOracle) GetPrice(honey uint64) (uint64, error) { | ||
// otherwise don't refresh the rate and return the latest price | ||
return honey * cpo.honeyPrice, nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2019 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package swap | ||
|
||
/* | ||
This module contains the pricing for message types as constants. | ||
Pricing in Swarm is defined in an internal unit. | ||
The name of this internal unit is honey. | ||
The honey unit allows to set prices of messages relative to each other | ||
without any dependancy to any currency. | ||
The expectation is then that an external, probably on-chain, **oracle** | ||
would be queried with the total amount of honey for a message, | ||
for which the oracle would return the price in a given currency. | ||
Currently the expected currency from the oracle would be wei, | ||
but it could potentially be any currency the oracle and Swarm support, | ||
allowing for a multi-currency design. | ||
*/ | ||
|
||
// Placeholder prices | ||
const ( | ||
RetrieveRequestMsgPrice = uint64(1) | ||
ChunkDeliveryMsgRetrievalPrice = uint64(1) | ||
// default convertion of honey into output currency - currently ETH | ||
defaultHoneyPrice = uint64(1) | ||
) |
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.