-
Notifications
You must be signed in to change notification settings - Fork 490
Description
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];
}
}
}