Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support functions for contract arguments #2270

Closed
richard-ramos opened this issue Feb 13, 2020 · 0 comments · Fixed by #2275
Closed

Support functions for contract arguments #2270

richard-ramos opened this issue Feb 13, 2020 · 0 comments · Fixed by #2275

Comments

@richard-ramos
Copy link
Member

richard-ramos commented Feb 13, 2020

Feature Request

Some contracts require dynamic arguments that are product of contract calls, or contain abi encoded data. Proxy contracts are one of those. When a proxy contract is created, you have the option of initializing the contract immediatly, instead of having to execute a separate transaction. Let's do a quick example.

Assume you have a proxy contract with the following interface:

contract Proxy {
     constructor(address contractLogic, bytes memory initData) { ... }
}

And you have a base contract like this:

contract MyContract {
    function initialize(uint _myValue, address _someAddress) public { ... }
}

With the current options embark provides, I have to do the initialization of the proxy contract by using an afterDeploy script:

// contracts.js
{
 ...
 MyContract: {
 },
 Proxy: {
     deploy: false
 },
 MyContractProxy: {
     instanceOf: "Proxy",
     proxyFor: "MyContract",
     args: ["$MyContract", "0x"]
 },
 afterDeploy: data
}
// data.js
// ...
const myValue = 34;
const someAddress = "0x124...567";
MyContract.methods.init(myValue, someAddress).send()

Ideally, this data script wouldnt be necessary if I were able to use the second argument of the proxy's constructor to execute the initialization as soon as the contract is deployed, by allowing the args in contract.js to accept a function that can return dynamic arguments like in this proposal:

// contracts.js
{
    MyContract: {
    },
    Proxy: {
     deploy: false
    },
   MyContractProxy: {
     instanceOf: "Proxy",
     proxyFor: "MyContract",
         args: deps => {
              const initABI = deps.contracts.MyContract.options.jsonInterface.find(x => x.type === 'function' && x.name == 'initialize');
              const myValue = 34;
              const someAddress = "0x124...567";
              const abiData = deps.web3.eth.abi.encodeFunctionCall(initABI, [myValue, someAddress]);
              return [deps.contracts.MyContract.options.address, abiData];
         }
    }
}
0x-r4bbit added a commit that referenced this issue Feb 18, 2020
… functions

This commit introduces a new feature that enables users to calculate Smart Contract
constructor arguments lazily using an (async) function. Similar to normal Smart Contract
configurations, the return or resolved value from that function has to be either a list
of arguments in the order as they are needed for the constructor, or as an object with
named members that match the arguments individually.

```
...
development: {
  deploy: {
    SimpleStorage: {
      args: async ({ contracts, web3, logger}) => {
        // do something with `contracts` and `web3` to determine
        // arguments
        let someValue = await ...;
        return [someValue];

        // or
        return {
          initialValue: someValue
        };
      }
    }
  }
}
...
```

Closes #2270
0x-r4bbit added a commit that referenced this issue Feb 20, 2020
… functions

This commit introduces a new feature that enables users to calculate Smart Contract
constructor arguments lazily using an (async) function. Similar to normal Smart Contract
configurations, the return or resolved value from that function has to be either a list
of arguments in the order as they are needed for the constructor, or as an object with
named members that match the arguments individually.

```
...
development: {
  deploy: {
    SimpleStorage: {
      args: async ({ contracts, web3, logger}) => {
        // do something with `contracts` and `web3` to determine
        // arguments
        let someValue = await ...;
        return [someValue];

        // or
        return {
          initialValue: someValue
        };
      }
    }
  }
}
...
```

Closes #2270
0x-r4bbit added a commit that referenced this issue Mar 2, 2020
… functions

This commit introduces a new feature that enables users to calculate Smart Contract
constructor arguments lazily using an (async) function. Similar to normal Smart Contract
configurations, the return or resolved value from that function has to be either a list
of arguments in the order as they are needed for the constructor, or as an object with
named members that match the arguments individually.

```
...
development: {
  deploy: {
    SimpleStorage: {
      args: async ({ contracts, web3, logger}) => {
        // do something with `contracts` and `web3` to determine
        // arguments
        let someValue = await ...;
        return [someValue];

        // or
        return {
          initialValue: someValue
        };
      }
    }
  }
}
...
```

Closes #2270
0x-r4bbit added a commit that referenced this issue Mar 3, 2020
… functions

This commit introduces a new feature that enables users to calculate Smart Contract
constructor arguments lazily using an (async) function. Similar to normal Smart Contract
configurations, the return or resolved value from that function has to be either a list
of arguments in the order as they are needed for the constructor, or as an object with
named members that match the arguments individually.

```
...
development: {
  deploy: {
    SimpleStorage: {
      args: async ({ contracts, web3, logger}) => {
        // do something with `contracts` and `web3` to determine
        // arguments
        let someValue = await ...;
        return [someValue];

        // or
        return {
          initialValue: someValue
        };
      }
    }
  }
}
...
```

Closes #2270
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant