Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

added enum to show error reason #131

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Binary file added .DS_Store
Binary file not shown.
Binary file added ethereum/.DS_Store
Binary file not shown.
Binary file added ethereum/contracts/.DS_Store
Binary file not shown.
68 changes: 67 additions & 1 deletion ethereum/contracts/coreRelayer/CoreRelayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,47 @@ import "./CoreRelayerDelivery.sol";
import "./CoreRelayerStructs.sol";

contract CoreRelayer is CoreRelayerDelivery {

enum ErrorReason {
SEND_ERROR,
FORWARD_ERROR,
MULTICHAIN_FORWARD_ERROR,
OTHER_ERROR
}

function getRefundAddressBalance(bytes32 refundAddress) public view returns (uint256) {
address payable account = payable(address(uint160(uint256(refundAddress))));
return account.balance;
}

uint256 leftoverFunds = getRefundAddressBalance(refundAddress);



IWormhole wormhole = wormhole();
uint256 wormholeMessageFee = wormhole.messageFee();



function getNeededValue(IWormholeRelayer.MultichainSend memory sendContainer) public view returns (uint256) {
// uint256 wormholeMessageFee = wormhole().messageFee();
uint256 totalMaxTransactionFee = 0;
uint256 totalReceiverValue = 0;

// Calculate the total maximum transaction fee and receiver value for all Send requests
for (uint256 i = 0; i < sendContainer.requests.length; i++) {
totalMaxTransactionFee += sendContainer.requests[i].maxTransactionFee;
totalReceiverValue += sendContainer.requests[i].receiverValue;
}

// Calculate the total needed value for the MultichainSend
uint256 neededValue = wormholeMessageFee + totalMaxTransactionFee + totalReceiverValue;
return neededValue;
}

uint256 needed_Value = getNeededValue(sendContainer);


/**
* @notice This 'send' function emits a wormhole message that alerts the default wormhole relay provider to
* call the receiveWormholeMessage(bytes[] memory vaas, bytes[] memory additionalData) endpoint of the contract on chain 'targetChain' and address 'targetAddress'
Expand Down Expand Up @@ -48,7 +89,10 @@ contract CoreRelayer is CoreRelayerDelivery {
nonce,
getDefaultRelayProvider()
);
}

if (!(maxTransactionFee >= quoteGas(targetChain, gasLimit, getDefaultRelayProvider()))){
revert(ErrorReason.SEND_ERROR); // send function error
}}

/**
* @notice This 'send' function emits a wormhole message that alerts a relay provider to
Expand Down Expand Up @@ -130,6 +174,11 @@ contract CoreRelayer is CoreRelayerDelivery {
nonce,
getDefaultRelayProvider()
);


if ((leftoverFunds + msg.value ) >= (maxTransactionFee + receiverValue + wormholeMessageFee)){
revert(ErrorReason.FORWARD_ERROR);
}
}

/**
Expand Down Expand Up @@ -223,6 +272,8 @@ contract CoreRelayer is CoreRelayerDelivery {

// Pay the relay provider
pay(relayProvider.getRewardAddress(), totalFee - wormholeMessageFee);


}

/**
Expand Down Expand Up @@ -285,6 +336,9 @@ contract CoreRelayer is CoreRelayerDelivery {
isValid: true
})
);
if (!(leftoverFunds>=needed_Value)) {
revert(ErrorReason.MULTICHAIN_FORWARD_ERROR); // multichain forward error
}
}

/**
Expand Down Expand Up @@ -439,4 +493,16 @@ contract CoreRelayer is CoreRelayerDelivery {
requests[0] = request;
container = IWormholeRelayer.MultichainSend({relayProviderAddress: relayProvider, requests: requests});
}

function getErrorMessage(ErrorReason reason) public pure returns (string memory) {
if (reason == ErrorReason.SEND_ERROR) {
return "Send transaction failed.";
} else if (reason == ErrorReason.FORWARD_ERROR) {
return "Error forwarding transaction.";
} else if (reason == ErrorReason.MULTICHAIN_FORWARD_ERROR) {
return "Error forwarding transaction to multiple chains.";
} else if (reason == ErrorReason.OTHER_ERROR) {
return "Unknown error occurred.";
}
}
}
Binary file added ethereum/contracts/libraries/.DS_Store
Binary file not shown.
68 changes: 68 additions & 0 deletions ethereum/yarn-error.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Arguments:
/Users/upendra/.nvm/versions/node/v16.17.1/bin/node /Users/upendra/.nvm/versions/node/v16.17.1/bin/yarn add node-forge

PATH:
/Users/upendra/.nvm/versions/node/v16.17.1/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Yarn version:
1.22.19

Node version:
16.17.1

Platform:
darwin arm64

Trace:
Error: ENOTDIR: not a directory, scandir '/Users/upendra/Desktop/developer/blockchain/openSource/trustlessGenericRelayer/tGR/trustless-generic-relayer/ethereum/node_modules'

npm manifest:
{
"name": "generic-relayer",
"version": "1.0.0",
"description": "",
"main": "networks.js",
"devDependencies": {
"@poanet/solidity-flattener": "^3.0.8",
"@typechain/ethers-v5": "^10.1.1",
"@types/chai": "^4.3.3",
"@types/koa": "^2.13.5",
"@types/koa-router": "^7.4.4",
"@types/mocha": "^9.1.1",
"chai": "^4.3.6",
"dotenv": "^16.0.3",
"ethers": "^5.7.1",
"mocha": "^10.0.0",
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.1"
},
"scripts": {
"build": "forge build -o build --via-ir",
"forge-test": "forge test -vvv --via-ir",
"integration-test": "bash shell-scripts/run_integration_tests.sh",
"load-test": "ENV=testnet ts-node ts-scripts/mockIntegrations/loadGeneration.ts",
"typechain": "bash ../sdk/scripts/make_ethers_types.sh",
"flatten": "mkdir -p node_modules/@poanet/solidity-flattener/contracts && cp -r contracts/* node_modules/@poanet/solidity-flattener/contracts/ && poa-solidity-flattener",
"deployAndConfigureTilt": "ENV=tilt bash ./ts-scripts/shell/deployConfigureTest.sh",
"readContractsTestnet": "ENV=testnet bash ./ts-scripts/shell/readContractStatus.sh",
"size": "forge build --sizes --force --via-ir"
},
"author": "",
"license": "ISC",
"dependencies": {
"@certusone/wormhole-sdk": "^0.9.6",
"@improbable-eng/grpc-web-node-http-transport": "^0.15.0",
"elliptic": "^6.5.4",
"jsonfile": "^6.1.0",
"koa": "^2.14.1",
"koa-router": "^12.0.0",
"prom-client": "^14.2.0",
"typescript": "^4.8.3"
}
}

yarn manifest:
No manifest

Lockfile:
No lockfile