Calling Agreements In Super Apps
Understanding CallAgreement vs CallAgreementWithContext
CallAgreement vs CallAgreementWithContext
TLDR
In Depth
require(
context.appAddress == msg.sender,
"SF: callAgreementWithContext from wrong address"
);//a function which we'll use to create a flow within a callback
function _createFlowInCallback(
bytes calldata ctx,
ISuperfluid _host,
IConstantFlowAgreementV1 _cfa,
ISuperfluidToken _acceptedToken,
address _receiver,
int96 _flowRate
)
private
returns (bytes memory newCtx)
{
newCtx = ctx;
(newCtx,) = _host.callAgreementwithContext(
_cfa,
abi.encodeWithSelector(
_cfa.deleteFlow.selector,
_acceptedToken,
address(this),
_receiver,
new bytes(0) // placeholder
),
"0x", //placeholder userdata value
newCtx //passing in the context from the super app callback
);
}
function afterAgreementCreated(
ISuperToken _superToken,
address _agreementClass,
bytes32, // _agreementId,
bytes calldata /*_agreementData*/,
bytes calldata ,// _cbdata,
bytes calldata _ctx
)
external override
onlyExpected(_superToken, _agreementClass)
onlyHost
returns (bytes memory newCtx)
{
//passing in the ctx which is sent to the callback here
return _createFlowInCallback(_ctx, _host, _cfa, _acceptedToken, _receiver, _flowrate);
}Last updated