Conversation
| ): AnyToNative | undefined { | ||
| ): | ||
| | ExtensionTypes.IExtension<ExtensionTypes.PnAnyToAnyConversion.ICreationParameters> | ||
| | undefined { |
There was a problem hiding this comment.
Unrelated but align with the method above.
| copiedExtensionState[extensionAction.id] = this.applyCreation(extensionAction, timestamp, { | ||
| extensionsState, | ||
| extensionAction, | ||
| requestState, | ||
| actionSigner, | ||
| }); |
There was a problem hiding this comment.
Necessary so we can call applyActionToExtension from the meta-pn context to create sub-pn states (see here).
| @@ -0,0 +1,243 @@ | |||
| import { ICurrencyManager } from '@requestnetwork/currency'; | |||
| @@ -0,0 +1,190 @@ | |||
| import { | |||
| @@ -55,6 +55,7 @@ const approvalSettings = { | |||
| const mnemonic = 'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat'; | |||
There was a problem hiding this comment.
There's a bit of duplication in the payment-processor tests file, but I didn't want to refactor them in this PR
| network: ChainName, | ||
| ) => Extension.IExtension<Extension.PnAnyToEth.ICreationParameters> | undefined; | ||
| network?: ChainName, | ||
| ) => Extension.IExtension<Extension.PnAnyToAnyConversion.ICreationParameters> | undefined; |
There was a problem hiding this comment.
Unrelated. There was a type mismatch that wasn't raised by typescript before
| actionSigner: Identity.IIdentity, | ||
| timestamp: number, | ||
| ) => RequestLogic.IExtensionStates; | ||
| createCreationAction: (parameters: TCreationParameters) => IAction<TCreationParameters>; |
There was a problem hiding this comment.
This method is public on all PN, but it wasn't exposed in this interface.
Exposing it allows to call it here
yomarion
left a comment
There was a problem hiding this comment.
(partial review, to be continued) Solid work and huge improvement to the lib 🚀
.../advanced-logic/test/utils/payment-network/erc20/any-to-erc20-proxy-create-data-generator.ts
Outdated
Show resolved
Hide resolved
alexandre-abrioux
left a comment
There was a problem hiding this comment.
Solid work, well done!
packages/advanced-logic/test/extensions/payment-network/meta.test.ts
Outdated
Show resolved
Hide resolved
MantisClone
left a comment
There was a problem hiding this comment.
Thanks for the PR @leoslr!
Here's a few comments and questions.
I've got to set it aside for today.I will continue my review tomorrow. I've only reviewed the payment-processor, types, and part of the advanced-logic. I haven't looked at payment-detection or any of the tests yet. And i'm still trying to wrap my head around the omission of the erc20-fee-proxy from the scope - especially whether the current design would prevent us from implementing it in the future.
packages/advanced-logic/test/extensions/payment-network/meta.test.ts
Outdated
Show resolved
Hide resolved
| sentRefundAmount: '0', | ||
| }); | ||
| // actions | ||
| export const actionCreationFull = { |
There was a problem hiding this comment.
Can you try to rename the fixtures in clear way so we can understand why adding a bitcoin payment is expected to throw, for instance? Example in this case createAnyToErc20Mainnet.
packages/advanced-logic/test/extensions/payment-network/meta.test.ts
Outdated
Show resolved
Hide resolved
| if (!pnIdentifier) throw new Error('Missing pn identifier'); | ||
|
|
||
| const extensionOfInterest: ExtensionTypes.IState | undefined = pn.values[pnIdentifier]; | ||
| if (!extensionOfInterest) throw new Error('Invalid pn identifier'); |
There was a problem hiding this comment.
Invalid is wrong, the ID might be valid but missing from the advanced logic state.
There was a problem hiding this comment.
I disagree, if the pnIdentifier is valid then it is in the advanced logic state.
Given a request, in state X. we should consider that the request is correct and does not miss data.
And the validity on pnIdentifier is based on X.
Otherwise, I can pass any pnIdentifier with any request, and it will never be considered invalid.
| }, | ||
| }; | ||
|
|
||
| export const validMetaRequest: ClientTypes.IRequestData = { |
There was a problem hiding this comment.
Can't you re-use the same fixture for encoder-payment.test.ts?
There was a problem hiding this comment.
The data from both test are not the same.
All the mocks should be shared in a common file, but this is already a big PR and I didn't want to include this mock refactoring as well.
Sharing the data between both file would require to update the associated tests as the expected recipient / currencies as well as
| expect(() => | ||
| encodeRequestPayment(validMetaRequest, provider, { | ||
| conversion: alphaConversionSettings, | ||
| pnIdentifier: 'unknown', |
There was a problem hiding this comment.
This test makes it look like it throws because "unknown" is an invalid pnId, but it would also through with "eth-input" for instance, which is valid but missing.
There was a problem hiding this comment.
eth-input is not valid the pnIdentifier within the meta-pn is a unique identifier to identify each sub-pn, it's not the payment network identifiers like any-to-erc20 eth-input ...
There was a problem hiding this comment.
The payment-detection package provides a getPaymentReference() utility function.
We need a new utility function to return all the sub-paymentReferences.
|
In the Also, will this feature require updates to the payment-subgraph? |
|
@MantisClone The |
Description of the changes
Context:
In the
Requestobject, theextensionsfield is of typeRecord<PN_ID, PN_STATE>.As a result, the same request can't contain twice the same payment network. This is a blocker if we want a USD request to be payable in both USDC-matic and USDC-mainnet as we would need twice the
pn-any-to-erc20.Meta payment network
This PR Introduces a new payment network:
META.Its purpose is to store information related to other payment networks.
This way we do not introduce breaking changes either at the request level, or at any of the existing payment network level.
Scope
For now the sub-payment network supported are only:
any-to-erc20-proxyany-to-eth-proxyany-to-declarativeSupporting the
erc20-fee-proxypn would require to add anetworkfield to it as it currently relies on therequest.currencyto determine the chain where the payment should happen.I didn't want to introduce the associated changes in this PR.
Furthermore, when there are several ways of paying a request, it's most likely denominated in FIAT.
It can always be added later on if needed.
Design
State of the Meta pn:
The key used to index each PN is the
saltof the associated PN. This data already exists, is unique and can easily be used to identify a PN within the meta-pn extension.Each sub-pn state contains the same data as it does when it is used as a standalone pn.
Actions of the Meta pn
This new PN has two actions:
createapply-action-to-pnThe create action perform basic validation regarding the meta-pn input data (e.g. uniqueness of each salt). Then it uses existing payment network to create individual sub-pn-state and index them using their associated salt.
The
apply-action-to-pnaction applies an action to one of the sub-pn. This is required, because when we create a pn, we allow for missing information (e.g. payment address) that can be added at a later time.If we don't have this action, it's not possible to add this information afterwards and the request will be unusable.
Same as the
createaction, it reuses all the capacities of existing payment networkPayment detection
To get the balance for the
meta-pnextension, we get the balance events of each sub-pn, then aggregate them. Reuse all of the existing logic.However, reusing everything means that there's a different
paymentReferencefor each sub-pn, as the salt of each sub-pn are different AND thepaymentAddressas well.Imo this is acceptable given the fact that the protocol already planned to have several
paymentReferenceper request (it's not the same whether we proceed to a payment or a refund see here)Payment processor
To build the transaction for the meta-pn extension, we pass the same properties as we currently do AND the key (salt) of the pn we wish to build the transaction for. It reuses all of the existing logic.