Skip to content

Commit

Permalink
Merge pull request #22 from pnetwork-association/chore/xerc20-tests
Browse files Browse the repository at this point in the history
Add xERC20 tests
  • Loading branch information
gitmp01 authored Aug 12, 2024
2 parents 7ca31ef + 19aa5d4 commit 17d0716
Show file tree
Hide file tree
Showing 17 changed files with 2,214 additions and 137 deletions.
Binary file modified docs/imgs/auth-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
754 changes: 754 additions & 0 deletions solidity/broadcast/Deploy.s.sol/1/run-latest.json

Large diffs are not rendered by default.

408 changes: 408 additions & 0 deletions solidity/broadcast/Deploy.s.sol/11155111/run-latest.json

Large diffs are not rendered by default.

526 changes: 526 additions & 0 deletions solidity/broadcast/Deploy.s.sol/56/run-latest.json

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions solidity/broadcast/ERC20.s.sol/1/transfer-latest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"transactions": [
{
"hash": "0xff34ec9f4234dba91c332690c09ed65fae2b486411ed3a5edfb76292fa97fc15",
"transactionType": "CALL",
"contractName": null,
"contractAddress": "0x6379ebd504941f50d5bfde9348b37593bd29c835",
"function": "transfer(address,uint256)",
"arguments": [
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"10000000000000000000"
],
"transaction": {
"from": "0xa0ee7a142d267c1f36714e4a8f75612f20a79720",
"to": "0x6379ebd504941f50d5bfde9348b37593bd29c835",
"gas": "0x1167a",
"value": "0x0",
"input": "0xa9059cbb000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000000000000000000000000000008ac7230489e80000",
"nonce": "0x1d",
"chainId": "0x1"
},
"additionalContracts": [],
"isFixedGasLimit": false
}
],
"receipts": [
{
"status": "0x1",
"cumulativeGasUsed": "0xc99e",
"logs": [
{
"address": "0x6379ebd504941f50d5bfde9348b37593bd29c835",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x000000000000000000000000a0ee7a142d267c1f36714e4a8f75612f20a79720",
"0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266"
],
"data": "0x0000000000000000000000000000000000000000000000008ac7230489e80000",
"blockHash": "0xed02cfa6b3e137d0e0494cdd54b64215c9306083dd499978ba2f3ecf8e473f84",
"blockNumber": "0xb",
"blockTimestamp": "0x66a8e65b",
"transactionHash": "0xff34ec9f4234dba91c332690c09ed65fae2b486411ed3a5edfb76292fa97fc15",
"transactionIndex": "0x0",
"logIndex": "0x0",
"removed": false
}
],
"logsBloom": "0x00000000000000000000040000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000008000000200000000000000000000000000100000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000200000000000000000000000002000000000004000000000000000000000000000000000000000000000000004000000000000000000000000",
"type": "0x2",
"transactionHash": "0xff34ec9f4234dba91c332690c09ed65fae2b486411ed3a5edfb76292fa97fc15",
"transactionIndex": "0x0",
"blockHash": "0xed02cfa6b3e137d0e0494cdd54b64215c9306083dd499978ba2f3ecf8e473f84",
"blockNumber": "0xb",
"gasUsed": "0xc99e",
"effectiveGasPrice": "0x12a8b971",
"blobGasPrice": "0x1",
"from": "0xa0ee7a142d267c1f36714e4a8f75612f20a79720",
"to": "0x6379ebd504941f50d5bfde9348b37593bd29c835",
"contractAddress": null,
"root": "0xb20c0af921641841cfc8e36e9d6e80957fd34c48e9db721bef83b73e61def40e"
}
],
"libraries": [],
"pending": [],
"returns": {},
"timestamp": 1722345051,
"chain": 1,
"commit": "f9e6adb"
}
3 changes: 3 additions & 0 deletions solidity/hardhat.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ module.exports = {
url: getEnvironmentVariable('BSC_RPC_URL'),
},
},
gasReporter: {
enabled: process.env.REPORT_GAS || false,
},
}

require('./tasks/index.cjs')
3 changes: 3 additions & 0 deletions solidity/script/Deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

./Script.sh "Deploy.s.sol" "$@"
18 changes: 18 additions & 0 deletions solidity/script/PAM.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Script.sol";
import "forge-std/console.sol";
import "../src/PAM.sol";

contract PAMScript is Script {
function setTeeSigner(
address pam,
bytes calldata pubKey,
bytes memory attestation
) external {
vm.startBroadcast();
PAM(pam).setTeeSigner(pubKey, attestation);
vm.stopBroadcast();
}
}
3 changes: 3 additions & 0 deletions solidity/script/PAM.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

./Script.sh "PAM.s.sol" "$@"
14 changes: 10 additions & 4 deletions solidity/script/XERC20.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@
pragma solidity ^0.8.13;

import "forge-std/Script.sol";
import {IXERC20} from "../src/interfaces/IXERC20.sol";
import {XERC20} from "../src/xerc20/XERC20.sol";

contract XERC20 is Script {
contract XERC20Script is Script {
function setLimits(
address xerc20,
address adapter,
uint256 mintingLimit,
uint256 burningLimit
) external {
vm.startBroadcast();
IXERC20(xerc20).setLimits(adapter, mintingLimit, burningLimit);
XERC20(xerc20).setLimits(adapter, mintingLimit, burningLimit);
vm.stopBroadcast();
}

function setLockbox(address xerc20, address lockbox) external {
vm.startBroadcast();
IXERC20(xerc20).setLockbox(lockbox);
XERC20(xerc20).setLockbox(lockbox);
vm.stopBroadcast();
}

function setPAM(address xerc20, address adapter, address pam) external {
vm.startBroadcast();
XERC20(xerc20).setPAM(adapter, pam);
vm.stopBroadcast();
}
}
26 changes: 26 additions & 0 deletions solidity/script/pegout.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

show_usage() {
echo "Usage:"
echo "$(basename "$0") <recipient> <token-address> <amount>"
}

if [[ -z "$1" ]]; then
echo "Invalid recipient"
show_usage
exit 1
fi

if [[ -z "$2" ]]; then
echo "Invalid token-address"
show_usage
exit 1
fi

if [[ -z "$3" ]]; then
echo "Invalid amount"
show_usage
exit 1
fi

cast calldata "pegOut(address,address,uint256)" "$1" "$2" "$3"
4 changes: 2 additions & 2 deletions solidity/src/Adapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ contract Adapter is IAdapter, Ownable {

uint256 _nonce;

address public erc20;
address public xerc20;
address public immutable erc20;
address public immutable xerc20;
mapping(bytes32 => bool) public pastEvents;

error NotAllowed();
Expand Down
6 changes: 2 additions & 4 deletions solidity/src/FeesManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,9 @@ contract FeesManager is IFeesManager, Ownable {
if (!info.defined) return 0;

uint256 fee = (amount * info.basisPoints) / 1000000;
uint256 minFee = feeInfoByAsset[xerc20].minFee;

return
fee < feeInfoByAsset[xerc20].minFee
? feeInfoByAsset[xerc20].minFee
: fee;
return fee < minFee ? minFee : fee;
}

/// @inheritdoc IFeesManager
Expand Down
10 changes: 6 additions & 4 deletions solidity/src/ptoken-v2/PTokenV2.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.2;
pragma experimental ABIEncoderV2;

import {IXERC20_solc_0_6 as IXERC20} from "./IXERC20-solc-0.6.sol";
import {IFeesManager_solc_0_6 as IFeesManager} from "./IFeesManager-solc-0.6.sol";
Expand All @@ -23,7 +24,7 @@ contract PTokenV2 is
// V2
uint256 private constant _DURATION = 1 days;
address public lockbox;
mapping(address => Bridge) bridges;
mapping(address => Bridge) public bridges;
address public feesManager;
mapping(address => address) public adapterToPAM;

Expand All @@ -49,9 +50,6 @@ contract PTokenV2 is
function setFeesManager(address newAddress) external override {
address msgSender = _msgSender();

if (feesManager == address(0) && msgSender != owner())
// First time
revert("OnlyOwner");
if (feesManager != address(0) && msgSender != feesManager)
revert("OnlyFeesManager");

Expand Down Expand Up @@ -117,6 +115,10 @@ contract PTokenV2 is
_burnWithCaller(msg.sender, _user, _amount);
}

function burn(uint256, bytes memory) public override {
revert("Not implemented");
}

/**
* @notice Sets the lockbox address
*
Expand Down
6 changes: 2 additions & 4 deletions solidity/src/ptoken-v2/PTokenV2NoGSN.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.2;
pragma experimental ABIEncoderV2;

import {IXERC20_solc_0_6 as IXERC20} from "./IXERC20-solc-0.6.sol";
import {IFeesManager_solc_0_6 as IFeesManager} from "./IFeesManager-solc-0.6.sol";
Expand Down Expand Up @@ -34,7 +35,7 @@ contract PTokenV2NoGSN is
// V2
uint256 private constant _DURATION = 1 days;
address public lockbox;
mapping(address => Bridge) bridges;
mapping(address => Bridge) public bridges;
address public feesManager;
mapping(address => address) public adapterToPAM;

Expand Down Expand Up @@ -86,9 +87,6 @@ contract PTokenV2NoGSN is
}

function setFeesManager(address newAddress) public override {
if (feesManager == address(0) && msg.sender != owner())
// First time
revert("OnlyOwner");
if (feesManager != address(0) && msg.sender != feesManager)
revert("OnlyFeesManager");

Expand Down
Loading

0 comments on commit 17d0716

Please sign in to comment.