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,

0 commit comments

Comments
 (0)