Skip to content

Commit 6524e02

Browse files
rodrigopavezigreptile-apps[bot]MantisClone
authored
refactor: update ERC20CommerceEscrowWrapper deployment script to support network-specific contract addresses (#1665)
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: MantisClone <david.huntmateo@request.network>
1 parent b4290f9 commit 6524e02

File tree

15 files changed

+75
-679
lines changed

15 files changed

+75
-679
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,7 @@ tsconfig.build.tsbuildinfo
4848
/packages/smart-contracts/.slither-cache/
4949
/packages/smart-contracts/crytic-export/
5050

51-
.nx-cache/
51+
.nx-cache/
52+
53+
# A place to store AI-generated or temporary files
54+
.ignore/

BASE_SEPOLIA_README.md

Lines changed: 0 additions & 198 deletions
This file was deleted.

packages/payment-detection/codegen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
overwrite: true
2-
schema: 'https://subgraph.satsuma-prod.com/e2e4905ab7c8/request-network--434873/request-payments-sepolia/api'
2+
schema: 'https://api.studio.thegraph.com/query/67444/request-payments-sepolia/version/latest'
33
documents: src/thegraph/queries/*.graphql
44
generates:
55
src/thegraph/generated/graphql.ts:

packages/payment-detection/src/thegraph/client.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ const THE_GRAPH_STUDIO_URL =
1111
const THE_GRAPH_EXPLORER_URL =
1212
'https://gateway.thegraph.com/api/$API_KEY/subgraphs/id/$SUBGRAPH_ID';
1313

14-
const THE_GRAPH_ALCHEMY_URL =
15-
'https://subgraph.satsuma-prod.com/e2e4905ab7c8/request-network--434873/request-payments-$NETWORK/api';
16-
1714
const THE_GRAPH_URL_MANTLE_TESTNET =
1815
'https://graph.testnet.mantle.xyz/subgraphs/name/requestnetwork/request-payments-mantle-testnet';
1916

@@ -23,19 +20,6 @@ const THE_GRAPH_URL_MANTLE =
2320
const THE_GRAPH_URL_CORE =
2421
'https://thegraph.coredao.org/subgraphs/name/requestnetwork/request-payments-core';
2522

26-
const THE_GRAPH_ALCHEMY_CHAINS: CurrencyTypes.ChainName[] = [
27-
'arbitrum-one',
28-
'avalanche',
29-
'base',
30-
'bsc',
31-
'fantom',
32-
'mainnet',
33-
'matic',
34-
'sepolia',
35-
'optimism',
36-
'zksyncera',
37-
];
38-
3923
const THE_GRAPH_EXPLORER_SUBGRAPH_ID: Partial<Record<CurrencyTypes.ChainName, string>> = {
4024
['arbitrum-one']: '3MtDdHbzvBVNBpzUTYXGuDDLgTd1b8bPYwoH1Hdssgp9',
4125
avalanche: 'A27V4PeZdKHeyuBkehdBJN8cxNtzVpXvYoqkjHUHRCFp',
@@ -159,10 +143,8 @@ export const getTheGraphClientUrl = (
159143
'$API_KEY',
160144
theGraphExplorerApiKey || '',
161145
).replace('$SUBGRAPH_ID', theGraphExplorerSubgraphId || '');
162-
const theGraphAlchemyUrl = THE_GRAPH_ALCHEMY_URL.replace('$NETWORK', chain);
163146

164147
const shouldUseTheGraphExplorer = !!theGraphExplorerApiKey && !!theGraphExplorerSubgraphId;
165-
const shouldUseAlchemy = THE_GRAPH_ALCHEMY_CHAINS.includes(chain);
166148

167149
switch (true) {
168150
case chain === 'private':
@@ -174,10 +156,6 @@ export const getTheGraphClientUrl = (
174156
case chain === 'core':
175157
return THE_GRAPH_URL_CORE;
176158
default:
177-
return shouldUseTheGraphExplorer
178-
? theGraphExplorerUrl
179-
: shouldUseAlchemy
180-
? theGraphAlchemyUrl
181-
: theGraphStudioUrl;
159+
return shouldUseTheGraphExplorer ? theGraphExplorerUrl : theGraphStudioUrl;
182160
}
183161
};

packages/payment-detection/test/thegraph/client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ describe('getTheGraphClientUrl', () => {
55
const url = getTheGraphClientUrl('base', { url: 'test' });
66
expect(url).toBe('test');
77
});
8-
it('should build the correct URL for network supported by Alchemy', () => {
8+
it('should build the correct URL for network using TheGraph Studio', () => {
99
const url = getTheGraphClientUrl('base');
1010
expect(url).toBe(
11-
'https://subgraph.satsuma-prod.com/e2e4905ab7c8/request-network--434873/request-payments-base/api',
11+
'https://api.studio.thegraph.com/query/67444/request-payments-base/version/latest',
1212
);
1313
});
1414
it('should build the correct URL when using TheGraph Explorer API key', () => {

packages/payment-processor/test/payment/erc20-commerce-escrow-wrapper.test.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const wallet = Wallet.fromMnemonic(mnemonic).connect(provider);
3232
const network: CurrencyTypes.EvmChainName = 'sepolia';
3333
const erc20ContractAddress = '0x9FBDa871d559710256a2502A2517b794B482Db40';
3434

35+
// Get the real wrapper address from the deployed contract
36+
const wrapperAddress = getCommerceEscrowWrapperAddress(network);
37+
3538
const mockAuthorizeParams: AuthorizePaymentParams = {
3639
paymentReference: '0x0123456789abcdef',
3740
payer: wallet.address,
@@ -75,7 +78,9 @@ describe('erc20-commerce-escrow-wrapper', () => {
7578
describe('getCommerceEscrowWrapperAddress', () => {
7679
it('should return address when wrapper is deployed on testnet', () => {
7780
const address = getCommerceEscrowWrapperAddress(network);
78-
expect(address).toBe('0x1234567890123456789012345678901234567890');
81+
// Verify it returns a valid Ethereum address
82+
expect(address).toMatch(/^0x[0-9a-fA-F]{40}$/);
83+
expect(address).not.toBe('0x0000000000000000000000000000000000000000');
7984
});
8085

8186
it('should throw when wrapper not found on mainnet', () => {
@@ -91,19 +96,12 @@ describe('erc20-commerce-escrow-wrapper', () => {
9196
}).toThrow('No deployment for network: unsupported-network.');
9297
});
9398

94-
it('should return different addresses for different supported networks', () => {
99+
it('should return a valid address for sepolia network', () => {
95100
const sepoliaAddress = getCommerceEscrowWrapperAddress('sepolia');
96-
const goerliAddress = getCommerceEscrowWrapperAddress('goerli');
97-
const mumbaiAddress = getCommerceEscrowWrapperAddress('mumbai');
98-
99-
// Verify all addresses are valid hex-formatted addresses
100-
[sepoliaAddress, goerliAddress, mumbaiAddress].forEach((addr) => {
101-
expect(addr).toMatch(/^0x[0-9a-fA-F]{40}$/);
102-
expect(addr).not.toBe('0x0000000000000000000000000000000000000000');
103-
});
104101

105-
// Verify all addresses are different
106-
expect(new Set([sepoliaAddress, goerliAddress, mumbaiAddress]).size).toBe(3);
102+
// Verify the address is valid hex-formatted address
103+
expect(sepoliaAddress).toMatch(/^0x[0-9a-fA-F]{40}$/);
104+
expect(sepoliaAddress).not.toBe('0x0000000000000000000000000000000000000000');
107105
});
108106
});
109107

@@ -226,7 +224,7 @@ describe('erc20-commerce-escrow-wrapper', () => {
226224
expect(result).toBe('1000000000000000000');
227225
expect(mockGetErc20Allowance).toHaveBeenCalledWith(
228226
wallet.address,
229-
'0x1234567890123456789012345678901234567890', // wrapper address
227+
wrapperAddress, // real wrapper address from deployment
230228
provider,
231229
erc20ContractAddress,
232230
);
@@ -631,7 +629,7 @@ describe('erc20-commerce-escrow-wrapper', () => {
631629
});
632630

633631
expect(wallet.sendTransaction).toHaveBeenCalledWith({
634-
to: '0x1234567890123456789012345678901234567890',
632+
to: wrapperAddress,
635633
data: expect.stringMatching(/^0x[a-fA-F0-9]+$/),
636634
value: 0,
637635
});
@@ -648,7 +646,7 @@ describe('erc20-commerce-escrow-wrapper', () => {
648646
});
649647

650648
expect(wallet.sendTransaction).toHaveBeenCalledWith({
651-
to: '0x1234567890123456789012345678901234567890',
649+
to: wrapperAddress,
652650
data: expect.stringMatching(/^0x[a-fA-F0-9]+$/),
653651
value: 0,
654652
});
@@ -665,7 +663,7 @@ describe('erc20-commerce-escrow-wrapper', () => {
665663
});
666664

667665
expect(wallet.sendTransaction).toHaveBeenCalledWith({
668-
to: '0x1234567890123456789012345678901234567890',
666+
to: wrapperAddress,
669667
data: expect.stringMatching(/^0x[a-fA-F0-9]+$/),
670668
value: 0,
671669
});
@@ -682,7 +680,7 @@ describe('erc20-commerce-escrow-wrapper', () => {
682680
});
683681

684682
expect(wallet.sendTransaction).toHaveBeenCalledWith({
685-
to: '0x1234567890123456789012345678901234567890',
683+
to: wrapperAddress,
686684
data: expect.stringMatching(/^0x[a-fA-F0-9]+$/),
687685
value: 0,
688686
});
@@ -699,7 +697,7 @@ describe('erc20-commerce-escrow-wrapper', () => {
699697
});
700698

701699
expect(wallet.sendTransaction).toHaveBeenCalledWith({
702-
to: '0x1234567890123456789012345678901234567890',
700+
to: wrapperAddress,
703701
data: expect.stringMatching(/^0x[a-fA-F0-9]+$/),
704702
value: 0,
705703
});
@@ -716,7 +714,7 @@ describe('erc20-commerce-escrow-wrapper', () => {
716714
});
717715

718716
expect(wallet.sendTransaction).toHaveBeenCalledWith({
719-
to: '0x1234567890123456789012345678901234567890',
717+
to: wrapperAddress,
720718
data: expect.stringMatching(/^0x[a-fA-F0-9]+$/),
721719
value: 0,
722720
});

0 commit comments

Comments
 (0)