Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
01a0afe
advanced-logic and payment-detection
yomarion Mar 19, 2023
0dfe034
fix import
yomarion Mar 19, 2023
c671f5d
chore: replaced rinkeby with matic for TheGraph codegen
yomarion Mar 19, 2023
8af51c7
added payment-detection test for balance
yomarion Mar 19, 2023
5288331
fix: thegraph codegen issues with superfluid
yomarion Mar 19, 2023
f8a60fd
Merge remote-tracking branch 'origin/master' into feat/erc20-fee-prox…
yomarion Mar 19, 2023
c22485c
fix: chain utils
yomarion Mar 19, 2023
b77d304
fix deleted file
yomarion Mar 19, 2023
7fe103b
fix artifact and tenderly related types
yomarion Mar 20, 2023
957e3c6
fix: Utils.isSameNetwork and test
yomarion Mar 20, 2023
cd5baa1
fix: payment-detection near versionMap
yomarion Mar 20, 2023
7092478
dirty-wip before inheriting the abstract class
yomarion Mar 21, 2023
411dd1e
working tests with ERC20NearFeeProxy detector
yomarion Mar 21, 2023
37c0e47
tests running with standard retriever design
yomarion Mar 21, 2023
9d78781
standard info retriever for native token detections
yomarion Mar 22, 2023
dc3fcca
minor type fix
yomarion Mar 22, 2023
e3ebcde
got rid of ERC20NearFeeProxy
yomarion Mar 22, 2023
aeb51d3
fix prettier
yomarion Mar 22, 2023
5454cd4
fix prettier
yomarion Mar 22, 2023
1a30b10
prettier nycrc files
yomarion Mar 22, 2023
4a54df9
fix: mock types
yomarion Mar 22, 2023
6e2b501
fix: wrong mocked advanced-logic types
yomarion Mar 22, 2023
83531e0
minor test fix
yomarion Mar 22, 2023
d1fd986
chore: reduce irrelevant strong typing in tests
yomarion Mar 23, 2023
e89e7de
chore: improve type details in payment detector
yomarion Mar 23, 2023
5a6b0ba
Merge branch 'master' into feat/erc20-fee-proxy-on-near
yomarion Mar 24, 2023
b6b39e9
Merge remote-tracking branch 'origin/master' into feat/erc20-fee-prox…
yomarion Mar 24, 2023
2e45994
fix: merge details
yomarion Mar 26, 2023
ebfe888
Strongly typing NearChainName 1/n
yomarion Mar 26, 2023
d4add72
Strongly typing NearChainName 2/n
yomarion Mar 26, 2023
db7f5a8
fix: test unit test not unit-testable
yomarion Mar 27, 2023
66fd5ae
Enforce TGetSubGraphClient usage
yomarion Mar 27, 2023
3dd4d96
tiny type fix
yomarion Mar 27, 2023
b2c542e
Merge remote-tracking branch 'origin/master' into feat/erc20-fee-prox…
yomarion Mar 29, 2023
c71835e
fixes Alex' feedback
yomarion Mar 30, 2023
87a1207
reset yarn.lock
yomarion Mar 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: improve type details in payment detector
  • Loading branch information
yomarion committed Mar 23, 2023
commit e89e7de6428bdf7d392bec0fcd27af8a726e7f48
49 changes: 28 additions & 21 deletions packages/payment-detection/src/erc20/fee-proxy-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,26 @@ export abstract class ERC20FeeProxyPaymentDetectorBase<
);
}

export type GetSubGraphClient = (
network: CurrencyTypes.ChainName,
) => TheGraphClient | TheGraphClient<'near'>;
export type TGetSubGraphClient<TChain> = TChain extends CurrencyTypes.EvmChainName
? PaymentNetworkOptions['getSubgraphClient']
: PaymentNetworkOptions<'near'>['getSubgraphClient'];

/**
* Handle payment networks with ERC20 fee proxy contract extension on EVM (default) or Near chains
*/
export class ERC20FeeProxyPaymentDetector<
TChain extends CurrencyTypes.VMChainName = CurrencyTypes.EvmChainName,
> extends ERC20FeeProxyPaymentDetectorBase {
private readonly getSubgraphClient: TGetSubGraphClient<TChain>;
protected readonly network: TChain | undefined;
private readonly getSubgraphClient: TChain extends CurrencyTypes.EvmChainName
? PaymentNetworkOptions['getSubgraphClient']
: PaymentNetworkOptions<'near'>['getSubgraphClient'];
// private readonly getSubgraphClient: PaymentNetworkOptions['getSubgraphClient'];
constructor({
advancedLogic,
currencyManager,
getSubgraphClient,
network,
}: ReferenceBasedDetectorOptions & {
network?: TChain;
getSubgraphClient: TChain extends CurrencyTypes.EvmChainName
? PaymentNetworkOptions['getSubgraphClient']
: PaymentNetworkOptions<'near'>['getSubgraphClient'];
getSubgraphClient: TGetSubGraphClient<TChain>;
}) {
super(
ExtensionTypes.PAYMENT_NETWORK_ID.ERC20_FEE_PROXY_CONTRACT,
Expand Down Expand Up @@ -139,16 +134,7 @@ export class ERC20FeeProxyPaymentDetector<

const subgraphClient = this.getSubgraphClient(paymentChain);
if (subgraphClient) {
const graphInfoRetriever = EvmChains.isChainSupported(paymentChain)
? new TheGraphInfoRetriever(subgraphClient as TheGraphClient, this.currencyManager)
: NearChains.isChainSupported(paymentChain) && this.network
? new NearInfoRetriever(subgraphClient as TheGraphClient<'near'>)
: undefined;
if (!graphInfoRetriever) {
throw new Error(
`Could not find graphInfoRetriever for chain ${paymentChain} in payment detector`,
);
}
const graphInfoRetriever = this.getInfoRetriever(paymentChain, subgraphClient);
return graphInfoRetriever.getTransferEvents({
eventName,
paymentReference,
Expand All @@ -158,7 +144,11 @@ export class ERC20FeeProxyPaymentDetector<
acceptedTokens: [requestCurrency.value],
});
} else {
EvmChains.assertChainSupported(paymentChain);
if (!EvmChains.isChainSupported(paymentChain)) {
throw new Error(
`Could not get a TheGraph-based info retriever for chain ${paymentChain} and RPC-based info retrievers are only compatible with EVM chains.`,
);
}
const proxyInfoRetriever = new ProxyInfoRetriever(
paymentReference,
proxyContractAddress,
Expand All @@ -174,4 +164,21 @@ export class ERC20FeeProxyPaymentDetector<
};
}
}

protected getInfoRetriever(
paymentChain: TChain,
subgraphClient: TheGraphClient | TheGraphClient<'near'>,
): TheGraphInfoRetriever | NearInfoRetriever {
const graphInfoRetriever = EvmChains.isChainSupported(paymentChain)
? new TheGraphInfoRetriever(subgraphClient as TheGraphClient, this.currencyManager)
: NearChains.isChainSupported(paymentChain) && this.network
? new NearInfoRetriever(subgraphClient as TheGraphClient<'near'>)
: undefined;
if (!graphInfoRetriever) {
throw new Error(
`Could not find graphInfoRetriever for chain ${paymentChain} in payment detector`,
);
}
return graphInfoRetriever;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type TransferEventsParams = {
};
/**
* Gets a list of transfer events for a set of Near payment details
* Retriever for ERC20 Fee Proxy and Native token payments.
* TheGraph-based etriever for ERC20 Fee Proxy and Native token payments.
*/
export class NearInfoRetriever implements ITheGraphBaseInfoRetriever<NearPaymentEvent> {
/**
Expand Down