Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9fa3d1e3e9 | |||
| d631939aa9 | |||
| ea37628539 | |||
| 8c8a9f62b9 |
@@ -1,5 +1,5 @@
|
|||||||
node_modules
|
node_modules
|
||||||
../.env
|
.env
|
||||||
.to_do.md
|
.to_do.md
|
||||||
|
|
||||||
#Hardhat files
|
#Hardhat files
|
||||||
|
|||||||
@@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
This directory contains the contract and unit tests for the `BandwidthGenerator` smart contract.
|
This directory contains the contract and unit tests for the `BandwidthGenerator` smart contract.
|
||||||
|
|
||||||
This contract allows users to generate Basic Bandwidth Credentials (BBCs) on the Nym cosmos blockchain using ERC20 representations of NYM as payment, utilising the Cosmos Gravity Bridge for cross-chain payment.
|
This contract allows users to generate Basic Bandwidth Credentials (BBCs) on the Nyx blockchain using ERC20 NYM as payment, utilising the Gravity Bridge for cross-chain payment.
|
||||||
|
|
||||||
BBCs are credentials that will be presented to Gateways by a Nym Client, and represent a certain amount of bandwidth which can be sent through the Nym Mixnet.
|
|
||||||
|
|
||||||
By default 1 NYM = 1 GB of bandwidth. The ratio of NYM - bandwidth is denominated in bytes, and represented in the smart contract by the `BytesPerToken` variable. This variable can be adjusted by the contract owner.
|
By default 1 NYM = 1 GB of bandwidth. The ratio of NYM - bandwidth is denominated in bytes, and represented in the smart contract by the `BytesPerToken` variable. This variable can be adjusted by the contract owner.
|
||||||
|
|
||||||
The amount of bandwidth bought is calculated according to the following formula:
|
The amount of bandwidth bought is calculated according to the following formula:
|
||||||
@@ -15,3 +13,17 @@ The amount of bandwidth bought is calculated according to the following formula:
|
|||||||
* `npm install`
|
* `npm install`
|
||||||
* `npx hardhat compile`
|
* `npx hardhat compile`
|
||||||
* `npx hardhat test`
|
* `npx hardhat test`
|
||||||
|
|
||||||
|
If you are planning to interact with contracts on either Rinkeby or mainnet, or deploy new contract instances, create an `.env` file with the following:
|
||||||
|
|
||||||
|
```
|
||||||
|
RINKEBY_URL=https://rinkeby.infura.io/v3/<INFURA_KEY>
|
||||||
|
MAINNET_URL=https://mainnet.infura.io/v3/<INFURA_KEY>
|
||||||
|
PRIV_KEY=<YOUR_PRIVATE_KEY>
|
||||||
|
ETHERSCAN_API_KEY=<ETHERSCAN_API_KEY>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Deployed addresses
|
||||||
|
Find deployed instances of the smart contract on the Rinkeby testnet and the Ethereum mainnet in `contractAddresses.json`.
|
||||||
|
|
||||||
|
This json file is automatically updated when any of the scripts in `scripts/mainnet` or `scripts/rinkeby` are run.
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"_format": "hh-sol-dbg-1",
|
"_format": "hh-sol-dbg-1",
|
||||||
"buildInfo": "../../../../../build-info/1f95016aa87f8376998977fedfcae017.json"
|
"buildInfo": "../../../../../build-info/42a2c6b57bbdc8d38c975cb15800dd3b.json"
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"_format": "hh-sol-dbg-1",
|
"_format": "hh-sol-dbg-1",
|
||||||
"buildInfo": "../../../../../build-info/1f95016aa87f8376998977fedfcae017.json"
|
"buildInfo": "../../../../../build-info/42a2c6b57bbdc8d38c975cb15800dd3b.json"
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"_format": "hh-sol-dbg-1",
|
"_format": "hh-sol-dbg-1",
|
||||||
"buildInfo": "../../../../../../build-info/1f95016aa87f8376998977fedfcae017.json"
|
"buildInfo": "../../../../../../build-info/42a2c6b57bbdc8d38c975cb15800dd3b.json"
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"_format": "hh-sol-dbg-1",
|
"_format": "hh-sol-dbg-1",
|
||||||
"buildInfo": "../../../../build-info/1f95016aa87f8376998977fedfcae017.json"
|
"buildInfo": "../../../../build-info/42a2c6b57bbdc8d38c975cb15800dd3b.json"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"_format": "hh-sol-cache-2",
|
"_format": "hh-sol-cache-2",
|
||||||
"files": {
|
"files": {
|
||||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/contracts/BandwidthGenerator.sol": {
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/contracts/BandwidthGenerator.sol": {
|
||||||
"lastModificationDate": 1643129770695,
|
"lastModificationDate": 1648818985185,
|
||||||
"contentHash": "642b72e2d50d565db7bc994cace3f5a0",
|
"contentHash": "cc45839db61ac60d7e8fe32ef9005eb3",
|
||||||
"sourceName": "contracts/BandwidthGenerator.sol",
|
"sourceName": "contracts/BandwidthGenerator.sol",
|
||||||
"solcConfig": {
|
"solcConfig": {
|
||||||
"version": "0.8.10",
|
"version": "0.8.10",
|
||||||
@@ -40,8 +40,8 @@
|
|||||||
"BandwidthGenerator"
|
"BandwidthGenerator"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/contracts/CosmosToken.sol": {
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/contracts/CosmosToken.sol": {
|
||||||
"lastModificationDate": 1642773899716,
|
"lastModificationDate": 1648465653397,
|
||||||
"contentHash": "fc5dd09fe73bc6cfece970f702a3aba1",
|
"contentHash": "fc5dd09fe73bc6cfece970f702a3aba1",
|
||||||
"sourceName": "contracts/CosmosToken.sol",
|
"sourceName": "contracts/CosmosToken.sol",
|
||||||
"solcConfig": {
|
"solcConfig": {
|
||||||
@@ -76,8 +76,8 @@
|
|||||||
"CosmosERC20"
|
"CosmosERC20"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/contracts/Gravity.sol": {
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/contracts/Gravity.sol": {
|
||||||
"lastModificationDate": 1642773899716,
|
"lastModificationDate": 1648465653397,
|
||||||
"contentHash": "0d6dae561f7b541bafb892b8593a08ac",
|
"contentHash": "0d6dae561f7b541bafb892b8593a08ac",
|
||||||
"sourceName": "contracts/Gravity.sol",
|
"sourceName": "contracts/Gravity.sol",
|
||||||
"solcConfig": {
|
"solcConfig": {
|
||||||
@@ -117,9 +117,9 @@
|
|||||||
"Gravity"
|
"Gravity"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/access/Ownable.sol": {
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/access/Ownable.sol": {
|
||||||
"lastModificationDate": 1641812554274,
|
"lastModificationDate": 1648741041841,
|
||||||
"contentHash": "4fe56b59ced59d87df6b796758f62895",
|
"contentHash": "8398972af73b4e9e5ff3b31cad86234f",
|
||||||
"sourceName": "@openzeppelin/contracts/access/Ownable.sol",
|
"sourceName": "@openzeppelin/contracts/access/Ownable.sol",
|
||||||
"solcConfig": {
|
"solcConfig": {
|
||||||
"version": "0.8.10",
|
"version": "0.8.10",
|
||||||
@@ -153,9 +153,9 @@
|
|||||||
"Ownable"
|
"Ownable"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/math/SafeMath.sol": {
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/math/SafeMath.sol": {
|
||||||
"lastModificationDate": 1641812554378,
|
"lastModificationDate": 1648741041848,
|
||||||
"contentHash": "5365090efc586b728719e562ebfed0d6",
|
"contentHash": "a6a9d6c1f662e922b82c1ba4d81cdd48",
|
||||||
"sourceName": "@openzeppelin/contracts/utils/math/SafeMath.sol",
|
"sourceName": "@openzeppelin/contracts/utils/math/SafeMath.sol",
|
||||||
"solcConfig": {
|
"solcConfig": {
|
||||||
"version": "0.8.10",
|
"version": "0.8.10",
|
||||||
@@ -187,9 +187,9 @@
|
|||||||
"SafeMath"
|
"SafeMath"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol": {
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol": {
|
||||||
"lastModificationDate": 1641812553614,
|
"lastModificationDate": 1648741041814,
|
||||||
"contentHash": "2cd550cedf51b8d294607dad5023d717",
|
"contentHash": "f48de0eaae9544072b8766e2eac528a7",
|
||||||
"sourceName": "@openzeppelin/contracts/token/ERC20/ERC20.sol",
|
"sourceName": "@openzeppelin/contracts/token/ERC20/ERC20.sol",
|
||||||
"solcConfig": {
|
"solcConfig": {
|
||||||
"version": "0.8.10",
|
"version": "0.8.10",
|
||||||
@@ -225,9 +225,9 @@
|
|||||||
"ERC20"
|
"ERC20"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol": {
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol": {
|
||||||
"lastModificationDate": 1641812554110,
|
"lastModificationDate": 1648741041831,
|
||||||
"contentHash": "0eac3e1a83ee62326ca007811285b274",
|
"contentHash": "302d9755e46bc69d7058b0cbe7185e37",
|
||||||
"sourceName": "@openzeppelin/contracts/token/ERC20/IERC20.sol",
|
"sourceName": "@openzeppelin/contracts/token/ERC20/IERC20.sol",
|
||||||
"solcConfig": {
|
"solcConfig": {
|
||||||
"version": "0.8.10",
|
"version": "0.8.10",
|
||||||
@@ -259,9 +259,9 @@
|
|||||||
"IERC20"
|
"IERC20"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
|
||||||
"lastModificationDate": 1641812554118,
|
"lastModificationDate": 1648741041831,
|
||||||
"contentHash": "aa1be06992a99bb7393b26a6af3c4dfb",
|
"contentHash": "909ab67fc5c25033fe6cd364f8c056f9",
|
||||||
"sourceName": "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol",
|
"sourceName": "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol",
|
||||||
"solcConfig": {
|
"solcConfig": {
|
||||||
"version": "0.8.10",
|
"version": "0.8.10",
|
||||||
@@ -295,9 +295,9 @@
|
|||||||
"IERC20Metadata"
|
"IERC20Metadata"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/Context.sol": {
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/Context.sol": {
|
||||||
"lastModificationDate": 1641812553346,
|
"lastModificationDate": 1648741041804,
|
||||||
"contentHash": "851485d5b925529b1a2f34a0be077891",
|
"contentHash": "5f2c5c4b6af2dd4551027144797bc8be",
|
||||||
"sourceName": "@openzeppelin/contracts/utils/Context.sol",
|
"sourceName": "@openzeppelin/contracts/utils/Context.sol",
|
||||||
"solcConfig": {
|
"solcConfig": {
|
||||||
"version": "0.8.10",
|
"version": "0.8.10",
|
||||||
@@ -329,9 +329,9 @@
|
|||||||
"Context"
|
"Context"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
|
||||||
"lastModificationDate": 1641812554370,
|
"lastModificationDate": 1648741041848,
|
||||||
"contentHash": "d37406082a74a9b6b114de522fcb6349",
|
"contentHash": "76814c83c32552ed2b521c816b4d801a",
|
||||||
"sourceName": "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol",
|
"sourceName": "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol",
|
||||||
"solcConfig": {
|
"solcConfig": {
|
||||||
"version": "0.8.10",
|
"version": "0.8.10",
|
||||||
@@ -366,9 +366,9 @@
|
|||||||
"SafeERC20"
|
"SafeERC20"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol": {
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol": {
|
||||||
"lastModificationDate": 1641812554322,
|
"lastModificationDate": 1648741041844,
|
||||||
"contentHash": "53fbff678f378956efcb207fa748eaa6",
|
"contentHash": "92f9448b23a90ea3bb932ee55cc3ccce",
|
||||||
"sourceName": "@openzeppelin/contracts/security/ReentrancyGuard.sol",
|
"sourceName": "@openzeppelin/contracts/security/ReentrancyGuard.sol",
|
||||||
"solcConfig": {
|
"solcConfig": {
|
||||||
"version": "0.8.10",
|
"version": "0.8.10",
|
||||||
@@ -400,9 +400,9 @@
|
|||||||
"ReentrancyGuard"
|
"ReentrancyGuard"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/Address.sol": {
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/Address.sol": {
|
||||||
"lastModificationDate": 1641812553270,
|
"lastModificationDate": 1648741041804,
|
||||||
"contentHash": "c5f6c4e4df069c789e7d84b4c3011913",
|
"contentHash": "4cff8b2ea0d958750786b4e3ca308445",
|
||||||
"sourceName": "@openzeppelin/contracts/utils/Address.sol",
|
"sourceName": "@openzeppelin/contracts/utils/Address.sol",
|
||||||
"solcConfig": {
|
"solcConfig": {
|
||||||
"version": "0.8.10",
|
"version": "0.8.10",
|
||||||
@@ -434,9 +434,9 @@
|
|||||||
"Address"
|
"Address"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/cryptography/ECDSA.sol": {
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/cryptography/ECDSA.sol": {
|
||||||
"lastModificationDate": 1641812553414,
|
"lastModificationDate": 1648741041808,
|
||||||
"contentHash": "197dbfaf7146845fa76331a4c9980e9f",
|
"contentHash": "395edffd6bb2b3ba29970d5814039654",
|
||||||
"sourceName": "@openzeppelin/contracts/utils/cryptography/ECDSA.sol",
|
"sourceName": "@openzeppelin/contracts/utils/cryptography/ECDSA.sol",
|
||||||
"solcConfig": {
|
"solcConfig": {
|
||||||
"version": "0.8.10",
|
"version": "0.8.10",
|
||||||
@@ -460,16 +460,52 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"imports": [
|
||||||
|
"../Strings.sol"
|
||||||
|
],
|
||||||
|
"versionPragmas": [
|
||||||
|
"^0.8.0"
|
||||||
|
],
|
||||||
|
"artifacts": [
|
||||||
|
"ECDSA"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/Strings.sol": {
|
||||||
|
"lastModificationDate": 1648741041848,
|
||||||
|
"contentHash": "9c54c6c065d9e590fdcdd72c451425b9",
|
||||||
|
"sourceName": "@openzeppelin/contracts/utils/Strings.sol",
|
||||||
|
"solcConfig": {
|
||||||
|
"version": "0.8.10",
|
||||||
|
"settings": {
|
||||||
|
"optimizer": {
|
||||||
|
"enabled": true,
|
||||||
|
"runs": 200
|
||||||
|
},
|
||||||
|
"outputSelection": {
|
||||||
|
"*": {
|
||||||
|
"*": [
|
||||||
|
"abi",
|
||||||
|
"evm.bytecode",
|
||||||
|
"evm.deployedBytecode",
|
||||||
|
"evm.methodIdentifiers"
|
||||||
|
],
|
||||||
|
"": [
|
||||||
|
"ast"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"imports": [],
|
"imports": [],
|
||||||
"versionPragmas": [
|
"versionPragmas": [
|
||||||
"^0.8.0"
|
"^0.8.0"
|
||||||
],
|
],
|
||||||
"artifacts": [
|
"artifacts": [
|
||||||
"ECDSA"
|
"Strings"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/contracts/test-contracts/TestCosmosToken.sol": {
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/contracts/test-contracts/TestCosmosToken.sol": {
|
||||||
"lastModificationDate": 1642773899716,
|
"lastModificationDate": 1648465653397,
|
||||||
"contentHash": "957b6079ee0d5a6e048fce8555c14dee",
|
"contentHash": "957b6079ee0d5a6e048fce8555c14dee",
|
||||||
"sourceName": "contracts/test-contracts/TestCosmosToken.sol",
|
"sourceName": "contracts/test-contracts/TestCosmosToken.sol",
|
||||||
"solcConfig": {
|
"solcConfig": {
|
||||||
@@ -504,8 +540,8 @@
|
|||||||
"TestCosmosERC20"
|
"TestCosmosERC20"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/contracts/test-contracts/TestGravity.sol": {
|
"/home/mx/dev/nym/nym/contracts/basic-bandwidth-generation/contracts/test-contracts/TestGravity.sol": {
|
||||||
"lastModificationDate": 1642773899716,
|
"lastModificationDate": 1648465653397,
|
||||||
"contentHash": "f24299c3acb20aff23914e16b7ba95e1",
|
"contentHash": "f24299c3acb20aff23914e16b7ba95e1",
|
||||||
"sourceName": "contracts/test-contracts/TestGravity.sol",
|
"sourceName": "contracts/test-contracts/TestGravity.sol",
|
||||||
"solcConfig": {
|
"solcConfig": {
|
||||||
|
|||||||
@@ -80,12 +80,12 @@ contract BandwidthGenerator is Ownable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Function to create a BBC for account owning the verification key on the Nym Cosmos Blockchain
|
* @dev Function to create a BBC for account owning the verification key on the Nyx Blockchain
|
||||||
* by transfering erc20NYM via the Gravity Bridge.
|
* by transfering erc20NYM via the Gravity Bridge.
|
||||||
* @param _amount Amount of erc20NYM tokens to spend on BBC - denominated in wei.
|
* @param _amount Amount of erc20NYM tokens to spend on BBC - denominated in wei.
|
||||||
* @param _verificationKey Verification key of account on Nym blockchain who is purchasing BBC.
|
* @param _verificationKey Verification key of account on Nyx blockchain who is purchasing BBC.
|
||||||
* @param _signedVerificationKey Number of erc20NYMs to spend signed by _verificationKey for auth on Cosmos Blockchain.
|
* @param _signedVerificationKey Number of erc20NYMs to spend signed by _verificationKey for auth on Cosmos Blockchain.
|
||||||
* @param _cosmosRecipient Address of the recipient of payment on Nym Cosmos Blockchain.
|
* @param _cosmosRecipient Address of the recipient of payment on Nyx Blockchain.
|
||||||
*/
|
*/
|
||||||
function generateBasicBandwidthCredential(uint256 _amount, uint256 _verificationKey, bytes memory _signedVerificationKey, string calldata _cosmosRecipient) public checkEnabled {
|
function generateBasicBandwidthCredential(uint256 _amount, uint256 _verificationKey, bytes memory _signedVerificationKey, string calldata _cosmosRecipient) public checkEnabled {
|
||||||
require(_signedVerificationKey.length == 64, "BandwidthGenerator: Signature doesn't have 64 bytes");
|
require(_signedVerificationKey.length == 64, "BandwidthGenerator: Signature doesn't have 64 bytes");
|
||||||
|
|||||||
Reference in New Issue
Block a user