Skip to content

Commit 85f330e

Browse files
committed
Merge branch 'master' into fix/btach-conversion-capped
2 parents 93b8bb6 + 6e0cfaf commit 85f330e

29 files changed

+398
-142
lines changed

packages/advanced-logic/src/extensions/payment-network/any-to-near.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { UnsupportedNetworkError } from './address-based';
44
import AnyToNativeTokenPaymentNetwork from './any-to-native';
55

66
const CURRENT_VERSION = '0.1.0';
7-
const supportedNetworks = ['aurora', 'aurora-testnet'];
7+
const supportedNetworks = ['aurora', 'aurora-testnet', 'near-testnet'];
88

99
export default class AnyToNearPaymentNetwork extends AnyToNativeTokenPaymentNetwork {
1010
public constructor(
@@ -26,6 +26,7 @@ export default class AnyToNearPaymentNetwork extends AnyToNativeTokenPaymentNetw
2626
case 'aurora':
2727
return this.isValidMainnetAddress(address);
2828
case 'aurora-testnet':
29+
case 'near-testnet':
2930
return this.isValidTestnetAddress(address);
3031
case undefined:
3132
return this.isValidMainnetAddress(address) || this.isValidTestnetAddress(address);

packages/advanced-logic/src/extensions/payment-network/near-native.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { UnsupportedNetworkError } from './address-based';
33
import NativeTokenPaymentNetwork from './native-token';
44

55
const CURRENT_VERSION = '0.2.0';
6-
const supportedNetworks = ['aurora', 'aurora-testnet'];
6+
const supportedNetworks = ['aurora', 'aurora-testnet', 'near-testnet'];
77

88
/**
99
* Implementation of the payment network to pay in Near based on input data.
@@ -27,6 +27,7 @@ export default class NearNativePaymentNetwork extends NativeTokenPaymentNetwork
2727
case 'aurora':
2828
return this.isValidMainnetAddress(address);
2929
case 'aurora-testnet':
30+
case 'near-testnet':
3031
return this.isValidTestnetAddress(address);
3132
case undefined:
3233
return this.isValidMainnetAddress(address) || this.isValidTestnetAddress(address);

packages/advanced-logic/test/extensions/payment-network/any-to-near.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ describe('extensions/payment-network/any-to-native-token', () => {
186186
network: 'another-chain',
187187
});
188188
}).toThrowError(
189-
`Payment network 'another-chain' is not supported by this extension (only aurora, aurora-testnet)`,
189+
`Payment network 'another-chain' is not supported by this extension (only aurora, aurora-testnet, near-testnet)`,
190190
);
191191
});
192192
it('throws when payment network is missing', () => {

packages/advanced-logic/test/extensions/payment-network/native-token.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@ describe('extensions/payment-network/native-token', () => {
2121
value: 'NEAR',
2222
network: 'aurora',
2323
};
24-
const nearTestnetCurrency = {
24+
const auroraTestnetCurrency = {
2525
type: RequestLogicTypes.CURRENCY.ETH,
2626
value: 'NEAR-testnet',
2727
network: 'aurora-testnet',
2828
};
29+
const nearTestnetCurrency = {
30+
type: RequestLogicTypes.CURRENCY.ETH,
31+
value: 'tNEAR',
32+
network: 'near-testnet',
33+
};
2934
const nativeTokenTestCases = [
3035
{
3136
name: 'Near',
@@ -34,14 +39,23 @@ describe('extensions/payment-network/native-token', () => {
3439
suffix: 'near',
3540
wrongSuffix: 'testnet',
3641
currency: nearCurrency,
37-
wrongCurrency: nearTestnetCurrency,
42+
wrongCurrency: auroraTestnetCurrency,
3843
},
3944
{
40-
name: 'Near testnet',
45+
name: 'Aurora testnet',
4146
paymentNetwork: new NearNativePaymentNetwork() as NativeTokenPaymentNetwork,
4247
networkName: 'aurora-testnet',
4348
suffix: 'testnet',
4449
wrongSuffix: 'near',
50+
currency: auroraTestnetCurrency,
51+
wrongCurrency: nearCurrency,
52+
},
53+
{
54+
name: 'Near testnet',
55+
paymentNetwork: new NearNativePaymentNetwork() as NativeTokenPaymentNetwork,
56+
networkName: 'near-testnet',
57+
suffix: 'testnet',
58+
wrongSuffix: 'near',
4559
currency: nearTestnetCurrency,
4660
wrongCurrency: nearCurrency,
4761
},
@@ -136,7 +150,7 @@ describe('extensions/payment-network/native-token', () => {
136150
paymentNetworkName: 'another-chain',
137151
});
138152
}).toThrowError(
139-
`Payment network 'another-chain' is not supported by this extension (only aurora, aurora-testnet)`,
153+
`Payment network 'another-chain' is not supported by this extension (only aurora, aurora-testnet, near-testnet)`,
140154
);
141155
});
142156
it('createCreationAction() throws without payment network', () => {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"0x775eb53d00dd0acd3ec1696472105d579b9b386b": {
3+
"0xed9cbb2837912278b47d422f36df40a1da36c4e0": 1
4+
},
5+
"0xed9cbb2837912278b47d422f36df40a1da36c4e0": {
6+
"0x775eb53d00dd0acd3ec1696472105d579b9b386b": 1
7+
}
8+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"0x775eb53d00dd0acd3ec1696472105d579b9b386b": {
3-
"0xed9cbb2837912278b47d422f36df40a1da36c4e0": 1
3+
"0x45b3b427996b7091243501ee0efdc4a8e9b03c53": 1
44
},
5-
"0xed9cbb2837912278b47d422f36df40a1da36c4e0": {
5+
"0x45b3b427996b7091243501ee0efdc4a8e9b03c53": {
66
"0x775eb53d00dd0acd3ec1696472105d579b9b386b": 1
77
}
88
}

packages/currency/src/conversion-aggregators.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import maticAggregator from './aggregators/matic.json';
99
import fantomAggregator from './aggregators/fantom.json';
1010
import nearAggregator from './aggregators/near.json';
1111
import nearTestnetAggregator from './aggregators/near-testnet.json';
12+
import auroraTestnetAggregator from './aggregators/aurora-testnet.json';
1213

1314
/**
1415
* currencyFrom => currencyTo => cost
@@ -35,7 +36,8 @@ const chainlinkCurrencyPairs: AggregatorsMap = {
3536
// Pairs supported by Flux Protocol
3637
const fluxCurrencyPairs: AggregatorsMap = {
3738
aurora: nearAggregator,
38-
'aurora-testnet': nearTestnetAggregator,
39+
'aurora-testnet': auroraTestnetAggregator,
40+
'near-testnet': nearTestnetAggregator,
3941
};
4042

4143
// FIX ME: This fix enables to get these networks registered in conversionSupportedNetworks.

packages/currency/src/currency-utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import { RequestLogicTypes } from '@requestnetwork/types';
1313
*/
1414
export const isValidNearAddress = (address: string, network?: string): boolean => {
1515
if (!network) {
16-
return isValidNearAddress(address, 'aurora') || isValidNearAddress(address, 'aurora-testnet');
16+
return (
17+
isValidNearAddress(address, 'aurora') ||
18+
isValidNearAddress(address, 'aurora-testnet') ||
19+
isValidNearAddress(address, 'near-testnet')
20+
);
1721
}
1822
// see link bellow for NEAR address specification
1923
// https://nomicon.io/DataStructures/Account.html
@@ -35,6 +39,7 @@ export const isValidNearAddress = (address: string, network?: string): boolean =
3539
case 'aurora':
3640
return !!address.match(/\.near$/);
3741
case 'aurora-testnet':
42+
case 'near-testnet':
3843
return !!address.match(/\.testnet$/);
3944
default:
4045
throw new Error(`Cannot validate NEAR address for network ${network}`);

packages/currency/src/currencyManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ export class CurrencyManager<TMeta = unknown> implements ICurrencyManager<TMeta>
237237
switch (currency.symbol) {
238238
case 'NEAR':
239239
case 'NEAR-testnet':
240+
case 'tNEAR':
240241
return isValidNearAddress(address, currency.network);
241242
default:
242243
// we don't pass a third argument to the validate method here

packages/currency/src/native.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ export const nativeCurrencies: Record<NativeCurrencyType, (NativeCurrency & { na
5757
name: 'Fantom',
5858
network: 'fantom',
5959
},
60-
{
61-
symbol: 'BNB',
62-
decimals: 18,
63-
name: 'BNB',
64-
network: 'bsctest',
65-
},
6660
{
6761
symbol: 'BNB',
6862
decimals: 18,
@@ -81,6 +75,12 @@ export const nativeCurrencies: Record<NativeCurrencyType, (NativeCurrency & { na
8175
name: 'Near Testnet',
8276
network: 'aurora-testnet',
8377
},
78+
{
79+
symbol: 'tNEAR',
80+
decimals: 24,
81+
name: 'Test Near',
82+
network: 'near-testnet',
83+
},
8484
{
8585
symbol: 'ARETH',
8686
decimals: 18,

packages/currency/test/currencyManager.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ describe('CurrencyManager', () => {
456456
const nearAddresses: Record<string, string> = {
457457
aurora: 'requestnetwork.near',
458458
'aurora-testnet': 'requestnetwork.testnet',
459+
'near-testnet': 'requestnetwork.testnet',
459460
};
460461

461462
const eip55Addresses: string[] = [
@@ -489,6 +490,13 @@ describe('CurrencyManager', () => {
489490
network: 'aurora-testnet',
490491
},
491492
},
493+
near: {
494+
tNEAR: {
495+
type: RequestLogicTypes.CURRENCY.ETH,
496+
symbol: 'tNEAR',
497+
network: 'near-testnet',
498+
},
499+
},
492500
};
493501

494502
const testValidateAddressForCurrency = (
@@ -520,6 +528,7 @@ describe('CurrencyManager', () => {
520528
switch (currency.symbol) {
521529
case 'NEAR':
522530
case 'NEAR-testnet':
531+
case 'tNEAR':
523532
testValidateAddressForCurrency(nearAddresses[currency.network], currency);
524533
break;
525534
default:

packages/payment-detection/src/eth/multichainExplorerApiProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class MultichainExplorerApiProvider extends ethers.providers.EtherscanPro
3333
case 'fuse':
3434
return 'https://explorer.fuse.io';
3535
case 'celo':
36-
return 'https://explorer.celo.org/mainnet';
36+
return 'https://api.celoscan.io';
3737
case 'matic':
3838
return 'https://api.polygonscan.com';
3939
case 'fantom':
@@ -46,6 +46,7 @@ export class MultichainExplorerApiProvider extends ethers.providers.EtherscanPro
4646
case 'aurora':
4747
return 'https://explorer.mainnet.near.org';
4848
case 'aurora-testnet':
49+
case 'near-testnet':
4950
return 'https://explorer.testnet.near.org';
5051
case 'arbitrum-rinkeby':
5152
return 'https://testnet.arbiscan.io/';

packages/payment-detection/src/near/near-conversion-detector.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ export class NearConversionNativeTokenPaymentDetector extends AnyToAnyDetector<
5151
'aurora-testnet': {
5252
'0.1.0': 'native.conversion.reqnetwork.testnet',
5353
},
54+
'near-testnet': {
55+
'0.1.0': 'native.conversion.reqnetwork.testnet',
56+
},
5457
};
5558
if (versionMap[chainName]?.[version]) {
5659
return versionMap[chainName][version];

packages/payment-detection/src/near/near-detector.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export class NearNativeTokenPaymentDetector extends ReferenceBasedDetector<
4141
'0.1.0': 'dev-1626339335241-5544297',
4242
'0.2.0': 'dev-1631521265288-35171138540673',
4343
},
44+
'near-testnet': {
45+
'0.1.0': 'dev-1626339335241-5544297',
46+
'0.2.0': 'dev-1631521265288-35171138540673',
47+
},
4448
};
4549
if (versionMap[chainName]?.[version]) {
4650
return versionMap[chainName][version];

packages/payment-detection/src/near/retrievers/near-info-retriever.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class NearInfoRetriever {
2525
protected eventName: PaymentTypes.EVENTS_NAMES,
2626
network: string,
2727
) {
28-
if (network !== 'aurora' && network !== 'aurora-testnet') {
28+
if (network !== 'aurora' && network !== 'aurora-testnet' && network !== 'near-testnet') {
2929
throw new Error('Near input data info-retriever only works with Near mainnet and testnet');
3030
}
3131

packages/payment-detection/src/payment-network-factory.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ const supportedPaymentNetwork: ISupportedPaymentNetworkByCurrency = {
5050
'aurora-testnet': {
5151
[PN_ID.NATIVE_TOKEN]: NearNativeTokenPaymentDetector,
5252
},
53+
'near-testnet': {
54+
[PN_ID.NATIVE_TOKEN]: NearNativeTokenPaymentDetector,
55+
},
5356
'*': {
5457
[PN_ID.ETH_INPUT_DATA]: EthInputDataPaymentDetector,
5558
[PN_ID.ETH_FEE_PROXY_CONTRACT]: EthFeeProxyPaymentDetector,

packages/payment-detection/src/thegraph/info-retriever.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ export class TheGraphInfoRetriever {
5050

5151
private filterPaymentEvents(payment: PaymentEventResultFragment, params: TransferEventsParams) {
5252
// Check contract address matches expected
53-
if (formatAddress(payment.contractAddress) !== params.contractAddress) {
53+
if (formatAddress(payment.contractAddress) !== formatAddress(params.contractAddress)) {
5454
return false;
5555
}
5656
// Check paid token tokens matches expected (conversion only)
5757
if (
5858
payment.tokenAddress &&
59+
params.acceptedTokens &&
60+
params.acceptedTokens.length > 0 &&
5961
!params.acceptedTokens?.includes(formatAddress(payment.tokenAddress, 'tokenAddress'))
6062
) {
6163
return false;

packages/payment-detection/test/erc20/fee-proxy-contract.test.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,77 @@ describe('api/erc20/fee-proxy-contract', () => {
365365
expect(parameters.gasUsed).toBe('79220');
366366
expect(parameters.gasPrice).toBe('1500000011');
367367
});
368+
369+
it('can retrieve payment using thegraph info retriever', async () => {
370+
const mockRequest: RequestLogicTypes.IRequest = {
371+
creator: { type: IdentityTypes.TYPE.ETHEREUM_ADDRESS, value: '0x2' },
372+
currency: {
373+
network: 'mainnet',
374+
type: RequestLogicTypes.CURRENCY.ERC20,
375+
value: '0x967da4048cd07ab37855c090aaf366e4ce1b9f48',
376+
},
377+
events: [],
378+
expectedAmount: '168040800000000000000000',
379+
extensions: {
380+
[ExtensionTypes.ID.PAYMENT_NETWORK_ERC20_FEE_PROXY_CONTRACT]: {
381+
events: [
382+
{
383+
name: 'create',
384+
parameters: {
385+
feeAddress: '0x35d0e078755Cd84D3E0656cAaB417Dee1d7939c7',
386+
feeAmount: '13386000000000000000',
387+
paymentAddress: '0x6c9E04997000d6A8a353951231923d776d4Cdff2',
388+
salt: 'c75c317e05c52f12',
389+
},
390+
timestamp: 1665989825,
391+
},
392+
],
393+
id: ExtensionTypes.ID.PAYMENT_NETWORK_ERC20_FEE_PROXY_CONTRACT,
394+
type: ExtensionTypes.TYPE.PAYMENT_NETWORK,
395+
values: {
396+
salt: 'c75c317e05c52f12',
397+
paymentAddress: '0x6c9E04997000d6A8a353951231923d776d4Cdff2',
398+
feeAddress: '0x35d0e078755Cd84D3E0656cAaB417Dee1d7939c7',
399+
feeAmount: '13386000000000000000',
400+
},
401+
version: '0.2.0',
402+
},
403+
},
404+
extensionsData: [],
405+
requestId: '01169f05b855a57396552cc0052b161f70590bdf9c5371649cd89a70c65fb586db',
406+
state: RequestLogicTypes.STATE.CREATED,
407+
timestamp: 0,
408+
version: '0.2',
409+
};
410+
erc20FeeProxyContract = new ERC20FeeProxyPaymentDetector({
411+
advancedLogic: mockAdvancedLogic,
412+
currencyManager,
413+
getSubgraphClient: () => ({
414+
GetPaymentsAndEscrowState: jest.fn().mockImplementation(({ reference }) => ({
415+
payments: [
416+
{
417+
contractAddress: '0x370de27fdb7d1ff1e1baa7d11c5820a324cf623c',
418+
tokenAddress: '0x967da4048cd07ab37855c090aaf366e4ce1b9f48',
419+
to: '0x6c9e04997000d6a8a353951231923d776d4cdff2',
420+
from: '0x15339d48fbe31e349a507fd6d48eb01c45fdc79a',
421+
amount: '168040800000000000000000',
422+
feeAmount: '13386000000000000000',
423+
reference: '0x5ac7241d9e6f419409e439c8429eea2f8f089d76528fd1d5df7496a3e58b5ce1',
424+
block: 15767215,
425+
txHash: '0x456d67cba236778e91a901e97c71684e82317dc2679d1b5c6bfa6d420d636b7d',
426+
gasUsed: '73152',
427+
gasPrice: '12709127644',
428+
},
429+
].filter((x) => x.reference.toLowerCase() === reference.toLowerCase()),
430+
escrowEvents: [],
431+
})),
432+
GetLastSyncedBlock: jest.fn(),
433+
GetSyncedBlock: jest.fn(),
434+
}),
435+
});
436+
437+
const { balance, error } = await erc20FeeProxyContract.getBalance(mockRequest);
438+
expect(error).toBeUndefined();
439+
expect(balance).toBe('168040800000000000000000');
440+
});
368441
});

packages/payment-detection/test/near/near-native-conversion.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { mocked } from 'ts-jest/utils';
1818
jest.mock('graphql-request');
1919
const graphql = mocked(GraphQLClient.prototype);
2020
const mockNearPaymentNetwork = {
21-
supportedNetworks: ['aurora', 'aurora-testnet'],
21+
supportedNetworks: ['aurora', 'aurora-testnet', 'near-testnet'],
2222
};
2323
const currencyManager = CurrencyManager.getDefault();
2424

@@ -199,7 +199,7 @@ describe('Near payments detection', () => {
199199
error: {
200200
code: 2,
201201
message:
202-
'Payment network unknown-network not supported by pn-any-to-native-token payment detection. Supported networks: aurora, aurora-testnet',
202+
'Payment network unknown-network not supported by pn-any-to-native-token payment detection. Supported networks: aurora, aurora-testnet, near-testnet',
203203
},
204204
events: [],
205205
});

0 commit comments

Comments
 (0)