Skip to content

Commit

Permalink
Merge pull request #15 from web3-nomad/feature/erc4626
Browse files Browse the repository at this point in the history
Vault contracts with utils file for interactions with HTS in tests
  • Loading branch information
maksimKrukovich authored Apr 4, 2024
2 parents 315411f + e61c0b7 commit fabfe98
Show file tree
Hide file tree
Showing 37 changed files with 4,097 additions and 2,829 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
env:
RPC_URL: ${{ secrets.RPC_URL }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
ACCOUNT_ID: ${{ secrets.ACCOUNT_ID }}

steps:
- uses: actions/checkout@v4
Expand All @@ -33,4 +34,8 @@ jobs:
run: yarn run compile

- name: Run Tests
run: yarn run test
run: yarn hardhat test test/erc3643/**/**.ts --network hardhat

- name: Run HTS Tests
run: yarn hardhat test test/erc4626/**.ts --network testnet

2 changes: 1 addition & 1 deletion .github/workflows/push_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
env:
RPC_URL: ${{ secrets.RPC_URL }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}

ACCOUNT_ID: ${{ secrets.ACCOUNT_ID }}

steps:
- uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
env:
RPC_URL: ${{ secrets.RPC_URL }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
ACCOUNT_ID: ${{ secrets.ACCOUNT_ID }}

steps:
- uses: actions/checkout@v4
Expand Down
23 changes: 23 additions & 0 deletions contracts/common/IERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

interface IERC20 {
function totalSupply() external view returns (uint);

function balanceOf(address account) external view returns (uint);

function transfer(address recipient, uint amount) external returns (bool);

function allowance(address owner, address spender) external view returns (uint);

function approve(address spender, uint amount) external returns (bool);

function transferFrom(
address sender,
address recipient,
uint amount
) external returns (bool);

event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
}
20 changes: 20 additions & 0 deletions contracts/common/hedera/ExpiryHelper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.5.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "./HederaTokenService.sol";
import "./FeeHelper.sol";

contract ExpiryHelper is FeeHelper {
function createAutoRenewExpiry(
address autoRenewAccount,
uint32 autoRenewPeriod
) internal view returns (IHederaTokenService.Expiry memory expiry) {
expiry.autoRenewAccount = autoRenewAccount;
expiry.autoRenewPeriod = autoRenewPeriod;
}

function createSecondExpiry(uint32 second) internal view returns (IHederaTokenService.Expiry memory expiry) {
expiry.second = second;
}
}
103 changes: 103 additions & 0 deletions contracts/common/hedera/FeeHelper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.5.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "./HederaTokenService.sol";
import "./HederaResponseCodes.sol";
import "./IHederaTokenService.sol";
import "./KeyHelper.sol";

contract FeeHelper is KeyHelper {
function createFixedHbarFee(
uint32 amount,
address feeCollector
) internal pure returns (IHederaTokenService.FixedFee memory fixedFee) {
fixedFee.amount = amount;
fixedFee.useHbarsForPayment = true;
fixedFee.feeCollector = feeCollector;
}

function createFixedTokenFee(
uint32 amount,
address tokenId,
address feeCollector
) internal pure returns (IHederaTokenService.FixedFee memory fixedFee) {
fixedFee.amount = amount;
fixedFee.tokenId = tokenId;
fixedFee.feeCollector = feeCollector;
}

function createFixedSelfDenominatedFee(
uint32 amount,
address feeCollector
) internal pure returns (IHederaTokenService.FixedFee memory fixedFee) {
fixedFee.amount = amount;
fixedFee.useCurrentTokenForPayment = true;
fixedFee.feeCollector = feeCollector;
}

function createFractionalFee(
uint32 numerator,
uint32 denominator,
bool netOfTransfers,
address feeCollector
) internal pure returns (IHederaTokenService.FractionalFee memory fractionalFee) {
fractionalFee.numerator = numerator;
fractionalFee.denominator = denominator;
fractionalFee.netOfTransfers = netOfTransfers;
fractionalFee.feeCollector = feeCollector;
}

function createFractionalFeeWithMinAndMax(
uint32 numerator,
uint32 denominator,
uint32 minimumAmount,
uint32 maximumAmount,
bool netOfTransfers,
address feeCollector
) internal pure returns (IHederaTokenService.FractionalFee memory fractionalFee) {
fractionalFee.numerator = numerator;
fractionalFee.denominator = denominator;
fractionalFee.minimumAmount = minimumAmount;
fractionalFee.maximumAmount = maximumAmount;
fractionalFee.netOfTransfers = netOfTransfers;
fractionalFee.feeCollector = feeCollector;
}

function createRoyaltyFeeWithoutFallback(
uint32 numerator,
uint32 denominator,
address feeCollector
) internal pure returns (IHederaTokenService.RoyaltyFee memory royaltyFee) {
royaltyFee.numerator = numerator;
royaltyFee.denominator = denominator;
royaltyFee.feeCollector = feeCollector;
}

function createRoyaltyFeeWithHbarFallbackFee(
uint32 numerator,
uint32 denominator,
uint32 amount,
address feeCollector
) internal pure returns (IHederaTokenService.RoyaltyFee memory royaltyFee) {
royaltyFee.numerator = numerator;
royaltyFee.denominator = denominator;
royaltyFee.amount = amount;
royaltyFee.useHbarsForPayment = true;
royaltyFee.feeCollector = feeCollector;
}

function createRoyaltyFeeWithTokenDenominatedFallbackFee(
uint32 numerator,
uint32 denominator,
uint32 amount,
address tokenId,
address feeCollector
) internal pure returns (IHederaTokenService.RoyaltyFee memory royaltyFee) {
royaltyFee.numerator = numerator;
royaltyFee.denominator = denominator;
royaltyFee.amount = amount;
royaltyFee.tokenId = tokenId;
royaltyFee.feeCollector = feeCollector;
}
}
Loading

0 comments on commit fabfe98

Please sign in to comment.