-
Notifications
You must be signed in to change notification settings - Fork 2
Initial Commit #1
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
Open
ksridharbabuus
wants to merge
7
commits into
singnet:master
Choose a base branch
from
ksridharbabuus:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e21198b
Initial Commit
ksridharbabuus cb6da56
Removed functions marked for deletion
ksridharbabuus c3dfb27
Cleaned up unwanted files
ksridharbabuus cee581f
Cleaned Test Code
ksridharbabuus 5933e03
Splitting Test cases
ksridharbabuus 81ed19a
updated ReadMe File
ksridharbabuus e3c2154
Added comments varaible name change
ksridharbabuus 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 hidden or 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,7 @@ | ||
build/npm-module | ||
build | ||
node_modules | ||
yarn-error.log | ||
npm-debug.log | ||
addresses.json | ||
/.vscode |
This file contains hidden or 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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 singnet | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains hidden or 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 +1,39 @@ | ||
# snet-cf-gateway | ||
# SNET-CF-Gateway Contracts | ||
|
||
[](https://circleci.com/gh/singnet/SNET-CF-Gateway-Contracts) | ||
|
||
Includes SingularityNET Crypto to Fiat contracts, migrations, tests | ||
|
||
## Contracts | ||
|
||
### CryptoToFiat | ||
* Contract that maintains a Crypto to fiat conversion for Service Providers and AI Developers. Consumers can use this service to convert the AGI received as part if their services utilization. | ||
|
||
## Requirements | ||
* [Node.js](https://github.com/nodejs/node) (8+) | ||
* [Npm](https://www.npmjs.com/package/npm) | ||
|
||
## Install | ||
|
||
### Dependencies | ||
```bash | ||
npm install | ||
``` | ||
|
||
### Compile | ||
```bash | ||
npm run compile | ||
``` | ||
|
||
### Test | ||
```bash | ||
npm run test | ||
``` | ||
|
||
## Package | ||
```bash | ||
npm run package-npm | ||
``` | ||
|
||
## Release | ||
Contract build artifacts are published to NPM: COMING SOON |
This file contains hidden or 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,151 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; | ||
import "openzeppelin-solidity/contracts/math/SafeMath.sol"; | ||
|
||
contract CryptoToFiat { | ||
|
||
using SafeMath for uint256; | ||
|
||
// Owner of the contract | ||
address public owner; | ||
|
||
// Configurable Parameters | ||
string public AGIPrice; // Price JSON | ||
uint256 public minBalance; | ||
uint256 public conversionUpperLimit; // Upper limit on the AGI conversion | ||
uint256 public txnLimitInBlocks; // Number of blocks to be wait between Transactions | ||
address public authorizer; // Authorizer address singing the conversion process | ||
|
||
// To store the last txn Block Number | ||
mapping(address => uint256) public lastTxnBlocks; | ||
|
||
// To store the total conversion amount | ||
mapping(address => uint256) public totalConvertedAmt; | ||
|
||
//Tokens which have been deposit into the contract | ||
mapping (address => uint256) public balances; | ||
|
||
// Address of token contract | ||
ERC20 public token; | ||
|
||
// Events | ||
event PriceUpdated(string price); | ||
event NewOwner(address owner); | ||
event ConfigurationUpdate(uint256 minBalance, uint256 conversionUpperLimit, uint256 txnLimitInBlocks); | ||
event DepositFunds(address indexed sender, uint256 amount); | ||
event WithdrawFunds(address indexed sender, uint256 amount); | ||
event TransferFunds(address indexed sender, address indexed receiver, uint256 amount); | ||
event ConvertFunds(address indexed sender, address indexed owner, uint256 amount); | ||
|
||
// Modifiers | ||
modifier onlyOwner() { | ||
require( | ||
msg.sender == owner, | ||
"Only owner can call this function." | ||
); | ||
_; | ||
} | ||
|
||
constructor (address _token) | ||
public | ||
{ | ||
token = ERC20(_token); | ||
owner = msg.sender; | ||
} | ||
|
||
function deposit(uint256 value) | ||
public | ||
returns(bool) | ||
{ | ||
require(token.transferFrom(msg.sender, this, value), "Unable to transfer token to the contract."); | ||
balances[msg.sender] = balances[msg.sender].add(value); | ||
emit DepositFunds(msg.sender, value); | ||
return true; | ||
} | ||
|
||
function withdraw(uint256 value) | ||
public | ||
returns(bool) | ||
{ | ||
require(balances[msg.sender] >= value, "Insufficient balance in the contract."); | ||
require(token.transfer(msg.sender, value), "Unable to transfer token from the contract."); | ||
balances[msg.sender] = balances[msg.sender].sub(value); | ||
emit WithdrawFunds(msg.sender, value); | ||
return true; | ||
} | ||
|
||
function transfer(address receiver, uint256 value) | ||
public | ||
returns(bool) | ||
{ | ||
require(balances[msg.sender] >= value, "Insufficient balance in the contract"); | ||
balances[msg.sender] = balances[msg.sender].sub(value); | ||
balances[receiver] = balances[receiver].add(value); | ||
|
||
emit TransferFunds(msg.sender, receiver, value); | ||
return true; | ||
} | ||
|
||
/** | ||
* @dev Initiates the conversion process. | ||
* @param value Amount to be converted. | ||
* @param totalClaimable Total claimable amount from MPE contract. | ||
* @param v Part of Authorizer Signature. | ||
* @param r Part of Authorizer Signature. | ||
* @param s Part of Authorizer Signature. | ||
*/ | ||
function initiateConversion(uint256 value, uint256 totalClaimable, uint8 v, bytes32 r, bytes32 s) | ||
public | ||
returns(bool) | ||
{ | ||
require(balances[msg.sender] >= value, "Insufficient balance in the contract"); | ||
require(balances[msg.sender] >= value.add(minBalance), "Minimum balance to be maintained in the contract"); | ||
require(value <= conversionUpperLimit, "Exceeding the conversion limit"); | ||
require(lastTxnBlocks[msg.sender] <= block.number.sub(txnLimitInBlocks), "Exceeding the number of transactions in given time"); | ||
require(totalConvertedAmt[msg.sender].add(value) <= totalClaimable, "Exceeding the claims made so far"); | ||
|
||
//compose the message which was signed | ||
bytes32 message = prefixed(keccak256(abi.encodePacked("__Conversion", this, msg.sender, totalClaimable, lastTxnBlocks[msg.sender]))); | ||
|
||
// check that the signature is from the authorizer | ||
address authAddress = ecrecover(message, v, r, s); | ||
require(authAddress == authorizer, "Invalid signature"); | ||
|
||
balances[msg.sender] = balances[msg.sender].sub(value); | ||
balances[owner] = balances[owner].add(value); | ||
|
||
lastTxnBlocks[msg.sender] = block.number; | ||
totalConvertedAmt[msg.sender] = totalConvertedAmt[msg.sender].add(value); | ||
|
||
// This event is monitored to initiate the fiat transfer based on AGIPrice field | ||
emit ConvertFunds(msg.sender, owner, value); | ||
return true; | ||
} | ||
|
||
|
||
function updateOwner(address _owner) public onlyOwner { | ||
owner = _owner; | ||
emit NewOwner(_owner); | ||
} | ||
|
||
function updatePrice(string memory _sPrice) public onlyOwner { | ||
AGIPrice = _sPrice; | ||
emit PriceUpdated(_sPrice); | ||
} | ||
|
||
function setConfigurations(address _authorizer, uint256 _minBalance, uint256 _conversionUpperLimit, uint256 _txnLimitInBlocks) public onlyOwner { | ||
authorizer = _authorizer; | ||
minBalance = _minBalance; | ||
conversionUpperLimit = _conversionUpperLimit; | ||
txnLimitInBlocks = _txnLimitInBlocks; | ||
emit ConfigurationUpdate(_minBalance, _conversionUpperLimit, _txnLimitInBlocks); | ||
} | ||
|
||
/// builds a prefixed hash to mimic the behavior of ethSign. | ||
function prefixed(bytes32 hash) internal pure returns (bytes32) | ||
{ | ||
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); | ||
} | ||
|
||
} |
This file contains hidden or 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,23 @@ | ||
pragma solidity ^0.4.23; | ||
|
||
contract Migrations { | ||
address public owner; | ||
uint public last_completed_migration; | ||
|
||
constructor() public { | ||
owner = msg.sender; | ||
} | ||
|
||
modifier restricted() { | ||
if (msg.sender == owner) _; | ||
} | ||
|
||
function setCompleted(uint completed) public restricted { | ||
last_completed_migration = completed; | ||
} | ||
|
||
function upgrade(address new_address) public restricted { | ||
Migrations upgraded = Migrations(new_address); | ||
upgraded.setCompleted(last_completed_migration); | ||
} | ||
} |
This file contains hidden or 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,5 @@ | ||
let Migrations = artifacts.require("./Migrations.sol"); | ||
|
||
module.exports = function(deployer) { | ||
deployer.deploy(Migrations); | ||
}; |
This file contains hidden or 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,12 @@ | ||
let CryptoToFiat = artifacts.require("./CryptoToFiat.sol"); | ||
let Contract = require("truffle-contract"); | ||
let TokenAbi = require("singularitynet-token-contracts/abi/SingularityNetToken.json"); | ||
let TokenNetworks = require("singularitynet-token-contracts/networks/SingularityNetToken.json"); | ||
let TokenBytecode = require("singularitynet-token-contracts/bytecode/SingularityNetToken.json"); | ||
let Token = Contract({contractName: "SingularityNetToken", abi: TokenAbi, networks: TokenNetworks, bytecode: TokenBytecode}); | ||
|
||
module.exports = function(deployer, network, accounts) { | ||
Token.setProvider(web3.currentProvider) | ||
Token.defaults({from: accounts[0], gas: 4000000}); | ||
deployer.deploy(Token, {overwrite: false}).then((TokenInstance) => deployer.deploy(CryptoToFiat, TokenInstance.address)); | ||
}; |
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.
Uh oh!
There was an error while loading. Please reload this page.