ethereum / langlab

MIT License
9 stars 5 forks source link

Make ERC20 Tokens a top-level concept? #12

Open chriseth opened 7 years ago

chriseth commented 7 years ago

Should ERC20 Tokens be a top-level concept just like Ether is?

markusvoelter commented 7 years ago

So would this mean that we'd have to automatically generate the functions that deal with handling such tokens?

Here's a fundamental question: would the notion of an "interface" be useful? An interface defines several methods that belong together. For example, those for an ERC20 token or those for running a decision process. A particular contract could implement several interfaces. Or, alternatively, would one model these differnet parts of a "system", let's say, an ERC20 token plus a decision, as separate contracts? If so, how do you express that they, together, make up a system? I have not seen mechanisms yet for either modularizing a contract and/or assembling systems from multiple (tightly collaborating) contracts.

chriseth commented 7 years ago

An ERC20 token certainly has a defined interface and I think that interfaces in general are very useful for abstraction. This story is more about making ERC20 tokens a built-in that does not require declaring its interface in a source file that needs to be imported.

My general feeling is that it would be useful to support systems of multiple contracts which are linked together by their addresses, perhaps declared in some deployment configuration file.

markusvoelter commented 7 years ago

Regarding interfaces: https://github.com/ethereum/langlab/issues/14 Regarding multi-contract systems: https://github.com/ethereum/langlab/issues/15

Regarding ERC20 specifically: are you suggesting to make this a built-in functionality like Ether? I.e., there are native methods on the context expressions? Or to make it a first-class language construct (like a process) and then generate the low-level functions?

chriseth commented 7 years ago

I'm not really sure what the best solution should be, but I think it should receive a much higher priority in the language itself than it dose in e.g. Solidity. In Solidity, you can do

TokenInterface(0x1234...).transfer(10, someOneElse);

but only if you define the TokenInterface interface at some point in your code.

markusvoelter commented 7 years ago

what kind of thing exactly is the

TokenInterface(0x1234...)....

?

chriseth commented 7 years ago

Ah sorry: It is an explicit cast from a plain address to a contract type. This is how you use it if you have a fixed address. In practice it would rather look like:

contract C {
   // ...
   function getRidOfTokens(TokenInterface tokenType, uint amount, address recipient) {
       tokenType.transfer(amount, recipient);
    }
}