Skip to content
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

use ignition deployment and group currency tasks #12

Merged
merged 6 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
NIL_RPC_ENDPOINT="http://127.0.0.1:8529/"
PRIVATE_KEY=""
WALLET_ADDR=""
# Configuration for interacting with the =nil; cluster

# Specify the RPC endpoint of your cluster
# For example, if your cluster's RPC endpoint is at "http://127.0.0.1:8529", set it as below
NIL_RPC_ENDPOINT: "http://127.0.0.1:8529"

# Specify the private key used for signing transactions
# This should be a hexadecimal string corresponding to your account's private key
PRIVATE_KEY: ""

# Specify the wallet address associated with your private key
# Wallets can be created using the =nil; CLI
# This address will be used for transactions on the =nil; network
WALLET_ADDR: "0x"
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 1
commit-message:
prefix: "deps"
labels:
- "dependencies"
allow:
- dependency-name: "@nilfoundation/hardhat-plugin"
29 changes: 29 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Format

on:
pull_request:
branches:
- main

jobs:
format:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install

- name: Run Format
run: npm run format
29 changes: 29 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Lint

on:
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install

- name: Run Lint
run: npm run lint
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

33 changes: 33 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"useTemplate": {
"level": "off"
}
}
}
},
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 80
},
"files": {
"ignore": [
"node_modules",
"artifacts",
"cache",
"typechain-types",
"ignition/deployments"
]
}
}
34 changes: 34 additions & 0 deletions contracts/Currency.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.0;

import "@nilfoundation/smart-contracts/contracts/NilCurrencyBase.sol";

contract Currency is NilCurrencyBase {

constructor(string memory _currencyName) payable {
// Revert if the currency name is an empty string
require(bytes(_currencyName).length > 0, "Currency name must not be empty");

tokenName = _currencyName;
}
receive() external payable {}

/**
* @dev Sends currency to a specified address
* This is a workaround until we are able to send external messages to smart contracts
* For production, consider implementing access control, such as Ownable from OpenZeppelin
*/
function sendCurrencyPublic(address to, uint256 currencyId, uint256 amount) public {
sendCurrencyInternal(to, currencyId, amount);
}

/**
* @dev Mints new currency
* This is a workaround until we are able to send external messages to smart contracts
* For production, consider implementing access control, such as Ownable from OpenZeppelin
*/
function mintCurrencyPublic(uint256 amount) public {
mintCurrencyInternal(amount);
}
}
12 changes: 0 additions & 12 deletions contracts/Token.sol

This file was deleted.

11 changes: 5 additions & 6 deletions contracts/UniswapV2Pair.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ pragma solidity ^0.8.0;
import "./interfaces/IUniswapV2Pair.sol";
import "./libraries/Math.sol";
import "./interfaces/IUniswapV2Factory.sol";
import "./interfaces/IUniswapV2Callee.sol";
import {NilCurrencyBase} from "./nil/NilCurrencyBase.sol";
import "@nilfoundation/smart-contracts/contracts/NilCurrencyBase.sol";
import "./libraries/SafeMath.sol";
import "./nil/Nil.sol";
import "@nilfoundation/smart-contracts/contracts/Nil.sol";

contract UniswapV2Pair is NilCurrencyBase, IUniswapV2Pair {
using SafeMath for uint;
Expand Down Expand Up @@ -44,7 +43,7 @@ contract UniswapV2Pair is NilCurrencyBase, IUniswapV2Pair {
}

function _safeTransfer(uint256 _tokenId, address _to, uint _value) private {
sendCurrencyInternalSync(_to, _tokenId, _value);
sendCurrencyInternal(_to, _tokenId, _value);
}

constructor() payable {
Expand Down Expand Up @@ -91,7 +90,7 @@ contract UniswapV2Pair is NilCurrencyBase, IUniswapV2Pair {
uint liquidity = numerator / denominator;
if (liquidity > 0)
mintCurrencyInternal(liquidity);
sendCurrencyInternalSync(feeTo, getCurrencyId(), liquidity);
sendCurrencyInternal(feeTo, getCurrencyId(), liquidity);
}
}
} else if (_kLast != 0) {
Expand Down Expand Up @@ -122,7 +121,7 @@ contract UniswapV2Pair is NilCurrencyBase, IUniswapV2Pair {
require(liquidity > 0, "UniswapV2: INSUFFICIENT_LIQUIDITY_MINTED");

mintCurrencyInternal(liquidity);
sendCurrencyInternalSync(to, getCurrencyId(), liquidity);
sendCurrencyInternal(to, getCurrencyId(), liquidity);
_update(balance0, balance1, _reserve0, _reserve1);
// if (feeOn) kLast = uint(reserve0).mul(reserve1); // reserve0 and reserve1 are p-to-date
emit Mint(msg.sender, amount0, amount1);
Expand Down
18 changes: 10 additions & 8 deletions contracts/UniswapV2Router01.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ pragma solidity ^0.8.0;
import './interfaces/IUniswapV2Router01.sol';
import './interfaces/IUniswapV2Factory.sol';
import './libraries/UniswapV2Library.sol';
import './nil/NilCurrencyBase.sol';
import './nil/Nil.sol';
import "./nil/Nil.sol";
import "@nilfoundation/smart-contracts/contracts/NilCurrencyBase.sol";
import "@nilfoundation/smart-contracts/contracts/Nil.sol";
import "./interfaces/IUniswapV2Pair.sol";

contract UniswapV2Router01 is IUniswapV2Router01, NilCurrencyBase {
Expand All @@ -18,6 +17,9 @@ contract UniswapV2Router01 is IUniswapV2Router01, NilCurrencyBase {
}

constructor(address _factory) public {
// Revert if the factory address is the zero address or an empty string
require(_factory != address(0), "Factory address cannot be the zero address");

factory = _factory;
}

Expand Down Expand Up @@ -45,8 +47,8 @@ contract UniswapV2Router01 is IUniswapV2Router01, NilCurrencyBase {
if (tokens.length != 2) {
revert("UniswapV2Router: Expect 2 tokens to add liquidity");
}
sendCurrencyInternalSync(pair, tokenAId, tokens[0].amount);
sendCurrencyInternalSync(pair, tokenBId, tokens[1].amount);
sendCurrencyInternal(pair, tokenAId, tokens[0].amount);
sendCurrencyInternal(pair, tokenBId, tokens[1].amount);
liquidity = IUniswapV2Pair(pair).mint(to);
amountA = tokens[0].amount;
amountB = tokens[1].amount;
Expand All @@ -72,7 +74,7 @@ contract UniswapV2Router01 is IUniswapV2Router01, NilCurrencyBase {
if (tokens.length != 1) {
revert("UniswapV2Router: should contains only pair token");
}
sendCurrencyInternalSync(pair, tokens[0].id, tokens[0].amount); // send liquidity to pair
sendCurrencyInternal(pair, tokens[0].id, tokens[0].amount); // send liquidity to pair
}

// **** SWAP ****
Expand Down Expand Up @@ -100,7 +102,7 @@ contract UniswapV2Router01 is IUniswapV2Router01, NilCurrencyBase {
require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT');
address pair = IUniswapV2Factory(factory).getTokenPair(path[0], path[1]);
Nil.Token[] memory tokens = Nil.msgTokens();
sendCurrencyInternalSync(pair, tokens[0].id, amounts[0]);
sendCurrencyInternal(pair, tokens[0].id, amounts[0]);
_swap(amounts, path, to);
}

Expand All @@ -115,7 +117,7 @@ contract UniswapV2Router01 is IUniswapV2Router01, NilCurrencyBase {
require(amounts[0] <= amountInMax, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT');
address pair = IUniswapV2Factory(factory).getTokenPair(path[0], path[1]);
Nil.Token[] memory tokens = Nil.msgTokens();
sendCurrencyInternalSync(pair, tokens[0].id, amounts[0]);
sendCurrencyInternal(pair, tokens[0].id, amounts[0]);
_swap(amounts, path, to);
}

Expand Down
Loading
Loading