Where event LogFeeTransfer is used in polygon contract? - solidity

When I decoded and checked a transaction's log about the polygon contract (0x0000000000000000000000000000000000001010), I found the signature like "LogFeeTransfer(address,address,address,uint256,uint256,uint256,uint256,uint256)".
However I can't find that polygon contract emits this event.
What's this event for and where is used in the contract?
Thank you.
I searched the contract source code on polygonscan for "emit LogFeeContract".

This address on Polygon most likely holds a precompiled contract - which is usually not written in Solidity but in language of the client software (Golang, JS, ...).
My guess is that it's just a Solidity representation of the original Golang (or any other) code, so that it doesn't confuse users that there is no contract on this address on PolygonScan even though this address is publicly known as the native token address.
The Golang implementation can also emit events, as it's literally part of the node client software.
I wasn't able to find any specific implementation in other language apart from Solidity, but my answer is based on the fact that the ...1010 address is within the range of reserved addresses for precompiled contracts on Ethereum - https://eips.ethereum.org/EIPS/eip-1352. Even though Polygon might technically ignore this EIP.
More info on precompiles: https://ethereum.stackexchange.com/search?q=precompiled

Related

It is possible to change BEP-20 smart contract code?

I have deployed a contract on the BEP-20 network and now I don't need mint and owner address transfer functionality.
So I want to remove these options from the "write contract" options list.
If it is possible if yes then what can I do?
Smart contract bytecode is immutable. Assuming that your contract is not a proxy but a regular contract - you cannot change the already deployed code.
After you've made the changes in your local code, you'll need to recompile it, and deploy to a new address.

How to avoid hardcoding contract address in Solidity

When looking at other team's smart contracts, I often see code like this:
address constant public token = address(0xabc123...);
Where the hexadecimal number is the address of an earlier-deployed smart contract. Coming from JS and C++ background, I'm not a fan of this because it effectively hardcodes what should be in a configuration file directly into the smart contract code. Several questions come to mind when I see code like this:
What if I want to deploy this to another EVM-compatible network?
What if I want to deploy this to testnet?
I'm still relatively new to Solidity, so it's possible I'm missing some feature of truffle that allows me to insert these strings at the time of deployment, but I didn't see this mentioned in any of the tutorials I went through. I would much rather have something like a JSON configuration file for testnet/mainnet/L2-chain/etc instead of having N versions of the same file with minor differences. How should I handle these cases?
You can have a variable (instead of a constant) containing the token address. And this variable can be set from a constructor.
So you can effectively pass the value from an environment variable to the contract constructor, to the contract storage.
Example:
.env
TOKEN_ADDRESS=0x123
deploy.js using Truffle (docs) for example
MyContract.new(process.env.TOKEN_ADDRESS)
You can also use Hardhat (docs) or any other library allowing you to deploy to any network depending on the config.
MyContract.sol
pragma solidity ^0.8;
contract MyContract {
address token;
constructor(address _token) {
token = _token;
}
}

How do I write proxy and implementation contracts that supports Chainlink functionality (Proxy Pattern via DELEGATECALL Solidity 0.6)

I have a Solidity smart contract which relies on Chainlink oracles for external data that has a lot of functionality code that does not need to be replicated on a per contract basis but does change the state of the contract instance, which is why I decided the proxy pattern using delegate calls makes the most sense. In the proxy pattern I only have to deploy the byte-code for my contracts functions once, and then all other instances of my contract will just delegate call to the implementation contract, and the only new information added to the block chain will be instance fields of that specific contract.
I am able to get an implementation contract deployed and point my deployed proxy to its functions, but then when I call the lock function on the proxy I fail the check require(owner == msg.sender,"Owner only") which doesnt make sense since delegate calls are supposed to pass msg.sender and I set the owner field to msg.sender in the proxy's constructor. If I remove the require, I can call the function without a revert but the locked and debugAddr fields are unchanged, even though the lock function should change them(I thought delegate call was executed in the context of the caller?). Does anyone know what is wrong with my proxy and implementation contracts? I can guess it is to do with memory layouts or the assembly im using to do delegate calls, but I am not yet on the level where I can use my googling skills to find out what is wrong, so if someone can spot where my proxy contract is incorrect/badly formatted please let me know.
Thanks,
Ben
Lock function code snippet
//Locks in the contract, buyer should have already provided data scientist an upload only API key and their model ID
function lock() public returns (bool success)
{
debugAddr = msg.sender;
uint tempStamp = now;
//THIS IS THE REQUIRE THAT FAILS WHEN IT SHOULDNT WHEN I UNCOMMENT THIS AND DEPLOY/RUN
require(msg.sender == owner, "Only owner can lock contract.");
//require(!locked, "Cannot lock contract that is already locked.");
//require(buyer != address(0),"No buyer to lock.");
//require(bytes(buyerModelName).length != 0,"No buyerModelName to lock.");
//require((tempStamp - startTimestamp) < 158400,"Cannot lock contract that was entered by buyer over 44 hours ago.");
//require((getWeekday(tempStamp) == 0) || (getWeekday(tempStamp) == 1 && getHour(tempStamp) < 14),"Contract can only be locked in between Sunday 00:00 UTC and Monday 14:00 UTC");
LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
//require(link.balanceOf(address(this)) >= totalFee, "Contract requires 0.5 LINK total to operate once locked, current LINK balance is under 0.5.");
locked = true;
return true;
}
Proxy contract with require commented(also see the contract's txs, you can see me call lock):
https://kovan.etherscan.io/address/0x1f805d559f6eb7d7b19bf0340db288503f448ae8
Implementation contract the proxy points to:
https://kovan.etherscan.io/address/0xfb41ea6452da396279cbd9d9d8c136121e38fab6
Proxy contract with require uncommented(also see the contract's txs, you can see me call lock, and the revert):
https://kovan.etherscan.io/address/0x2d59aa0c1dd9a77d592167c43f2e65adcb275bfe
Implementation contract the proxy points to:
0x20a1f27d69f7a257741eddaec433642194af0215
Proxy Code and Implementation Code
Referenced Code: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/Proxy.sol
Proxy: https://github.com/benschreyer/Steak/blob/main/SteakQuarterly/ProxyPattern/SteakQuarterlyProxy.sol
Important Note In my proxy I do not want to declare the contract as a ChainlinkClient since then ChainlinkClient's functions will be included in the proxy which is unnecessary as the implementation should have those methods already. Instead I only declare the fields and of ChainlinkClient on my own. I feel like this is a prime place for my implementation to be wrong, but I am not sure what needs to change/if this is even feasible
Implementation: https://github.com/benschreyer/Steak/blob/main/SteakQuarterly/ProxyPattern/SteakQuarterlyDelegate.sol
EDIT: MINIMAL CODE EXAMPLE THAT STILL FAILS
This contract should have the minimal requirements to be a proxy for a ChainlinkClient and only has the lock function and a constructor, I get the same revert on require(owner == msg.sender). If I remove the require, the call to lock on the proxy contract says confirmed, but the proxy's state variables remain unchanged (debugAddr is 0, locked stays false)
Here is the minimal example code(I deployed on remix IDE compiled 0.6.12, the proxy's lock function was called by using at address retrieval with the delegate code compiled so that the abi of the delegate is used): https://github.com/benschreyer/Steak/tree/main/MinimalCodeExample
EDIT 2:
If I remove the ChainlinkClient portion/fields of my proxy and implementation minimum examples as linked above, I get a proxy contract that works and can accept external function calls defined in the implementation contract as it should.
So my question now is how do I write proxy and implementation contract that supports Chainlink GET request functionality? What fields/constants/events/interfaces does my proxy need defined or imported and where should I define/import them to allow for Chainlink to work? For example if I wanted to have my contract retrieve the temperature in Paris from an API via Chainlink, but also be a proxy so that I do not have to redploy all its functions and save on gas price.
Anything I have tried so far(see minimal breaking example) does not work once I add Chainlink into the mix, as I am not sure about how to structure the Proxy contract class so that the storage of the proxy and the access/write of the delegate call to the implementation line up. Here is the minimal code that works after I remove Chainlink functionality:
https://github.com/benschreyer/Steak/tree/main/MinimalCodeExample/WorkingButNoChainlink
A version of my working example proxy/implementation pattern contracts but with Chainlink functionality, or pointers on what fields/events/cosntant the proxy contract needs in order for it to make calls to oracles would be much appreciated.
Instead of defining the fields of ChainlinkClient in your proxy class, write a class ChainlinkClientStorage that holds the fields of ChainlinkClient, then declare your Proxy as inheriting from ChainlinkClientStorage
https://github.com/benschreyer/Steak/blob/main/SteakQuarterly/ProxyPattern/ChainlinkClientStorage.sol
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/Proxy.sol
contract MyProxy is ChainlinkClientStorage, MyContractStorage{}

What is the definition of "WCF endpoint"?

I know, I know, but before you vote to close because this 3-year-old question is the same: neither its answers, nor any of the dozens of other answers I've read and reread across the wide wide web, really define the term, at least not in a way that would earn a respectable grade on a language exam administered in a human-language class. (Technical writers appear to have a whole different idea of what "is" is.)
All due respect, consider the most-upvoted answer in that thread, which begins
An endpoint is what a service exposes, and in WCF terms, is made up of
three things...
Okay, that's how it's utilized and what its attributes are. What is it? It's an address, a binding, and a contract, easy as A-B-C! Any good student knows a "Binding" is just an(other) abstruse term for a communication mechanism, and a "Contract" is actually part of the service itself. So an endpoint must be defined by the "Address"!
The URL by which the endpoint can be reached.
Um... then how about the canonical Lowy answer, also cited in that thread. An excerpt of the part that doesn't repeat the above:
The endpoint is the fusion of the address, contract, and binding.
Every endpoint must have all three elements, and the host exposes the
endpoint.
That's like saying a duck is the fusion of walking like a duck, quacking like a duck, and looking like a duck, and the animal kingdom exposes the duck.
All snark aside, this is not idle gadfly curiosity: it is very hard to master a concept whose explanations fail to explain it. So, what is an endpoint in WCF?
An endpoint is really is an aggregation of these things, it's not an entity or concept that exists in its own right as such.
To extend your duck analogy, it's more like trying to define the quack itself - a quack is the aggregation of air moving over the duck's vocal cords, travelling through space and being interpretted by your brain. There is no "quack" you can point at and define separately outside of those terms.
An endpoint represents something that an external client call to ask your service to do something and (optionally) get some answer or data returned. As Ladislav says it's an "entry point to service functionality".
In order to define what a client can call upon you to do you need a contract (interface definition). To define how the client should send the data and receive the answer you need a binding. To define where the request must be sent you define the address.
If you don't define one of those you don't have an endpoint.
We simply say an "endpoint is exposed" as shorthand for "the service defines contract "C", with binding "B" at address "A" (the ABC's) ", that's all there is to it.
Endpoint is physical interface (boundary) for your service which has three main properties
Address which you must use to reach the service
Binding = set of configurations you must follow to be able to communicate with the service
Contract = set of operations which you can call on the service
Service can have multiple endpoints with different ABC.
Btw. it is not WCF term. WCF brought this term from WSDL.
Endpoint usually is the contract the service are using - the interface it are using.

WCF Business logic handling

I have a WCF service that supports about 10 contracts, we have been supporting a client with all the business rules specific to this client now we have another client who will be using the exact same contracts (so we cannot change that) they will be calling the service exactly the same way the previous client called now the only way we can differentiate between the two clients is by one of the input parameters. Based on this input parameter we have to use a slightly different business logic – the logic for both the Client will be same 50% of the time the remainder will have different logic (across Business / DAL layers) . I don’t want to use if else statement in each of contract implementation to differentiate and reroute the logic also what if another client comes in. Is there a clean way of handling a situation like this. I am using framework 3.5. Like I said I cannot change any of the contracts (service / data contract ) or the current service calling infrastructure for the new client. Thanks
Can you possibly host the services twice and have the clients connect to the right one? Apart from that, you have to use some kind of if-else, I guess.
I can't say whether this is applicable to you, but we have solved a similar problem along this path:
We add a Header information to the message that states in which context some logic is called.
This information ends up in a RequestContext class.
We delegate responsibility of instantiating the implementation of the contract to a DI Container (in our case StructureMap)
We have defined a strategy how certain components are to be provided by the container:
There is a default for a component of some kind.
Attributes can be placed on specializations that denote for which type of request context this specialization should be used.
This is registered into the container through available mechanisms
We make a call to the Container by stating ObjectFactory.With(requestcontext).getInstance<CONTRACT>()
Dependencies of the service implementations are now resolved in a way that the described process is applied. That is, specializations are provided based ultimately on a request information placed in the header.
This is an example how this may be solvable.