Commit 1b488d41 authored by Kegan's avatar Kegan
Browse files

initial commit. Note testnet account used for arbitrum rinkeby isn't important so can be leaked

parents
node_modules
.env
#Hardhat files
cache
artifacts
# Basic Sample Hardhat Project
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts.
Try running some of the following tasks:
```shell
npx hardhat accounts
npx hardhat compile
npx hardhat clean
npx hardhat test
npx hardhat node
node scripts/sample-script.js
npx hardhat help
```
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "hardhat/console.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/utils/Address.sol";
contract SteamToEther is Context {
using Address for address;
mapping(uint64 => address[]) internal steamIdToEther;
mapping(address => uint64) internal etherToSteamID;
constructor() {
console.log("Deployed SteamToEtherContract!");
}
function GetSteamAccount(address _addr) public view returns(uint64) {
require(!_addr.isContract(), "Contracts cannot link steam accounts!");
return etherToSteamID[_addr];
}
function GetEthereumWallets(uint64 _steamId) public view returns (address[] memory) {
require(_steamId > 0, "Cannot have 0 for steamid!");
return steamIdToEther[_steamId];
}
event AccountLinked(address _wallet, uint64 _steamId64);
function LinkSteamAccount(uint64 _steamId64) public {
address sender = _msgSender();
require(!sender.isContract(),"Contacts cannot link steam accounts!");
require(_steamId64 > 0, "Cannot have 0 for steam id!");
console.log("Linking steam account....");
//remove eth wallet from previous steamid association
uint64 old_steamid = etherToSteamID[sender];
if(old_steamid > 0)
{
for(uint256 i = 0; i < steamIdToEther[old_steamid].length; i++)
{
if(steamIdToEther[old_steamid][i] == sender)
{
steamIdToEther[old_steamid][i] = steamIdToEther[old_steamid][steamIdToEther[old_steamid].length-1]; //move last element into the position of our item we want to remove
steamIdToEther[old_steamid].pop(); //delete last item which is now a duplicate
}
}
}
//update eth->steamid list
etherToSteamID[sender] = _steamId64;
//if steamid->eth list does not already contain our sender then add
bool exists = false;
for(uint256 i = 0; i < steamIdToEther[_steamId64].length; i++)
{
if(steamIdToEther[_steamId64][i] == sender)
{
exists = true;
break;
}
}
if(!exists)
{
steamIdToEther[_steamId64].push(sender);
}
console.log("Account linked!");
emit AccountLinked(sender, _steamId64);
}
}
require("@nomiclabs/hardhat-waffle");
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
defaultNetwork: "arbitrum_testnet",
networks: {
hardhat: {
},
arbitrum_testnet: {
url: 'https://rinkeby.arbitrum.io/rpc',
gasPrice: 0,
accounts: ['bfbe3c8e88593d6e1231eb56fde14ac643ce9c34f5fd8711f3720df582d0df40'],
},
},
solidity: {
version: "0.8.4",
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
},
paths: {
sources: "./contracts",
tests: "./test",
cache: "./cache",
artifacts: "./artifacts"
},
mocha: {
timeout: 20000
}
};
This diff is collapsed.
{
"name": "hardhat-project",
"dependencies": {
"hardhat": "^2.6.2"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/contracts": "^4.3.1",
"@openzeppelin/hardhat-upgrades": "^1.10.0",
"chai": "^4.3.4",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.4.6"
}
}
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
async function main() {
// Hardhat always runs the compile task when running scripts with its command
// line interface.
//
// If this script is run directly using `node` you may want to call compile
// manually to make sure everything is compiled
// await hre.run('compile');
// We get the contract to deploy
const SteamToEther = await hre.ethers.getContractFactory("SteamToEther");
const ste = await SteamToEther.deploy();
await ste.deployed();
console.log("Greeter deployed to:", ste.address);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
async function main() {
// Hardhat always runs the compile task when running scripts with its command
// line interface.
//
// If this script is run directly using `node` you may want to call compile
// manually to make sure everything is compiled
// await hre.run('compile');
// We get the contract to deploy
const ste = await hre.ethers.getContractAt("SteamToEther",'0xa3146718b0b9F2175e8a7F306b88B0c0DE5ABadE');
console.log(ste);
await ste.LinkSteamAccount('12345671234567890');
console.log("Steam account linked!");
let linked_wallets = await ste.GetEthereumWallets('12345671234567890');
console.log(linked_wallets);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
const { expect } = require("chai");
const { BigNumber } = require("ethers");
const { ethers } = require("hardhat");
describe("SteamToEther", function () {
it("Should add a new steam account link", async function () {
const SteamToEther = await ethers.getContractFactory("SteamToEther");
const ste = await SteamToEther.deploy();
await ste.deployed();
console.log('linking account');
await ste.LinkSteamAccount('12345671234567890');
console.log('testing get eth wallets');
expect(await ste.GetEthereumWallets('12345671234567890')).to.eql(['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266']);
console.log('testing valid steam account');
expect(await ste.GetSteamAccount('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266')).to.equal('12345671234567890');
console.log('testing invalid steam account');
expect(await ste.GetSteamAccount('0xBcd4042DE499D14e55001CcbB24a551F3b954096')).to.equal('0');
console.log('testing eth wallets');
expect(await ste.GetEthereumWallets('12345671234567891')).to.eql([]);
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment