Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
dc410f6
WIP
alexandre-abrioux Jan 31, 2023
ed3b672
WIP
alexandre-abrioux Feb 3, 2023
924a70e
fixes
alexandre-abrioux Feb 3, 2023
4aee325
Merge branch 'master' into networks
alexandre-abrioux Feb 3, 2023
bae4830
fix ERC20 order
alexandre-abrioux Feb 3, 2023
e7ecfb9
fix indentation
alexandre-abrioux Feb 3, 2023
8771389
fix tests
alexandre-abrioux Feb 3, 2023
d48802d
rollback changes
alexandre-abrioux Feb 3, 2023
753fe99
fix tests
alexandre-abrioux Feb 3, 2023
5bc4f96
fix tests
alexandre-abrioux Feb 3, 2023
5363d3c
fix tests
alexandre-abrioux Feb 3, 2023
256b6df
fix tests
alexandre-abrioux Feb 3, 2023
21b92fc
rollback test
alexandre-abrioux Feb 3, 2023
7bd75c7
fix tests
alexandre-abrioux Feb 3, 2023
b2ed93b
Merge branch 'master' into networks
alexandre-abrioux Feb 7, 2023
d6ae451
remove aurora from evm
alexandre-abrioux Feb 7, 2023
c7b3112
remove unused export
alexandre-abrioux Feb 7, 2023
e52eb10
fix missing export
alexandre-abrioux Feb 7, 2023
a446daf
change chaindefinition type name
alexandre-abrioux Feb 7, 2023
f454936
edit README
alexandre-abrioux Feb 7, 2023
05ab7d5
refactor chain types to classes
alexandre-abrioux Feb 7, 2023
ddf73ac
fix test
alexandre-abrioux Feb 7, 2023
94cf0e8
remove unusued utils
alexandre-abrioux Feb 7, 2023
c3d01ad
fix some more types
alexandre-abrioux Feb 7, 2023
ead5d9b
fix some more types
alexandre-abrioux Feb 7, 2023
a9a3029
fix test types
alexandre-abrioux Feb 7, 2023
737aee6
fix test
alexandre-abrioux Feb 7, 2023
f44f683
fix near typing
alexandre-abrioux Feb 7, 2023
87c5cd0
fix currencyManager
alexandre-abrioux Feb 7, 2023
3d7c730
fix aggregators type
alexandre-abrioux Feb 7, 2023
2b1fd4f
fix aggregators type
alexandre-abrioux Feb 8, 2023
9baa2f8
fix chainlink test
alexandre-abrioux Feb 8, 2023
100f709
rollback currency manager change
alexandre-abrioux Feb 8, 2023
1c240b7
rollback addagregator change
alexandre-abrioux Feb 8, 2023
729096e
fix ArtifactDeploymentInfo
alexandre-abrioux Feb 8, 2023
97b3438
fix type for ERC20Currency
alexandre-abrioux Feb 16, 2023
8f56b91
Merge branch 'master' into networks
alexandre-abrioux Feb 16, 2023
3452fd1
add README
alexandre-abrioux Feb 16, 2023
71f0809
Merge branch 'master' into networks
alexandre-abrioux Feb 22, 2023
9c014a9
Merge remote-tracking branch 'origin/master' into networks
alexandre-abrioux Mar 7, 2023
8d815f0
fix build
alexandre-abrioux Mar 7, 2023
51030c1
fix missing type
alexandre-abrioux Mar 7, 2023
0190ec2
Merge branch 'master' into networks
alexandre-abrioux Mar 7, 2023
0b99099
fix type errors
alexandre-abrioux Mar 7, 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
fix near typing
  • Loading branch information
alexandre-abrioux committed Feb 7, 2023
commit f44f6834fda9b541115132ad7ad892e9a5037c12
4 changes: 2 additions & 2 deletions packages/currency/src/chains/ChainsAbstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export abstract class ChainsAbstract<
* Check if chainName lives amongst the list of supported chains by this chain type.
* Throws in the case it's not supported.
*/
public assertChainSupported(chainName: string): asserts chainName is CHAIN_NAME {
if (!(this.chainNames as string[]).includes(chainName))
public assertChainSupported(chainName?: string): asserts chainName is CHAIN_NAME {
if (!chainName || !(this.chainNames as string[]).includes(chainName))
throw new Error(`Unsupported chain ${chainName}`);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/currency/src/chains/near/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import * as NearTestnetDefinition from './data/near-testnet';
export type NearChain = Chain;

export const chains: Record<CurrencyTypes.NearChainName, NearChain> = {
aurora: NearDefinition, // FIXME: aurora should be removed from near chains (it is a mistake)
'aurora-testnet': NearTestnetDefinition, // FIXME: aurora should be removed from near chains (it is a mistake)
near: NearDefinition,
aurora: NearDefinition,
'aurora-testnet': NearTestnetDefinition,
// near: NearDefinition, // TODO: add support for near
'near-testnet': NearTestnetDefinition,
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ export class NearConversionNativeTokenPaymentDetector extends AnyToNativeDetecto
super(args);
}

public static getContractName = (chainName: string, paymentNetworkVersion = '0.1.0'): string => {
public static getContractName = (
chainName: CurrencyTypes.NearChainName,
paymentNetworkVersion = '0.1.0',
): string => {
const version =
NearConversionNativeTokenPaymentDetector.getVersionOrThrow(paymentNetworkVersion);
const versionMap: Record<string, Record<string, string>> = {
const versionMap: Record<CurrencyTypes.NearChainName, Record<string, string>> = {
aurora: { '0.1.0': 'native.conversion.reqnetwork.near' },
'aurora-testnet': {
'0.1.0': 'native.conversion.reqnetwork.testnet',
Expand Down Expand Up @@ -63,7 +66,7 @@ export class NearConversionNativeTokenPaymentDetector extends AnyToNativeDetecto
address: string | undefined,
paymentReference: string,
requestCurrency: RequestLogicTypes.ICurrency,
paymentChain: CurrencyTypes.EvmChainName,
paymentChain: CurrencyTypes.NearChainName,
paymentNetwork: ExtensionTypes.IState<ExtensionTypes.PnAnyToEth.ICreationParameters>,
): Promise<PaymentTypes.AllNetworkRetrieverEvents<PaymentTypes.ETHPaymentNetworkEvent>> {
if (!address) {
Expand Down
7 changes: 5 additions & 2 deletions packages/payment-detection/src/near/near-detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ export class NearNativeTokenPaymentDetector extends NativeTokenPaymentDetector {
super(args);
}

public static getContractName = (chainName: string, paymentNetworkVersion = '0.2.0'): string => {
public static getContractName = (
chainName: CurrencyTypes.NearChainName,
paymentNetworkVersion = '0.2.0',
): string => {
const version = NearNativeTokenPaymentDetector.getVersionOrThrow(paymentNetworkVersion);
const versionMap: Record<string, Record<string, string>> = {
const versionMap: Record<CurrencyTypes.NearChainName, Record<string, string>> = {
aurora: { '0.1.0': 'requestnetwork.near', '0.2.0': 'requestnetwork.near' },
'aurora-testnet': {
'0.1.0': 'dev-1626339335241-5544297',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PaymentTypes } from '@requestnetwork/types';
import { getTheGraphNearClient, TheGraphClient } from '../../thegraph';
import { NearChains } from '@requestnetwork/currency';

// FIXME#1: when Near subgraphes can retrieve a txHash, replace the custom IPaymentNetworkEvent with PaymentTypes.ETHPaymentNetworkEvent
interface NearSubGraphPaymentEvent extends PaymentTypes.IETHPaymentEventParameters {
Expand All @@ -25,7 +26,9 @@ export class NearInfoRetriever {
protected eventName: PaymentTypes.EVENTS_NAMES,
network: string,
) {
if (network !== 'aurora' && network !== 'aurora-testnet' && network !== 'near-testnet') {
try {
NearChains.assertChainSupported(network);
} catch {
throw new Error('Near input data info-retriever only works with Near mainnet and testnet');
}

Expand Down
3 changes: 2 additions & 1 deletion packages/payment-processor/src/payment/near-conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
processNearPaymentWithConversion,
} from './utils-near';
import { IConversionPaymentSettings } from '.';
import { CurrencyManager, UnsupportedCurrencyError } from '@requestnetwork/currency';
import { CurrencyManager, NearChains, UnsupportedCurrencyError } from '@requestnetwork/currency';

/**
* Processes the transaction to pay a request in NEAR with on-chain conversion.
Expand Down Expand Up @@ -48,6 +48,7 @@ export async function payNearConversionRequest(
if (!network || !isNearNetwork(network)) {
throw new Error('Should be a Near network');
}
NearChains.assertChainSupported(network);

const amountToPay = getAmountToPay(request, amount).toString();
const version = getPaymentExtensionVersion(request);
Expand Down
6 changes: 4 additions & 2 deletions packages/payment-processor/src/payment/near-input-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { WalletConnection } from 'near-api-js';
import { ClientTypes, ExtensionTypes } from '@requestnetwork/types';

import {
getRequestPaymentValues,
validateRequest,
getAmountToPay,
getPaymentExtensionVersion,
getRequestPaymentValues,
validateRequest,
} from './utils';
import { INearTransactionCallback, isNearNetwork, processNearPayment } from './utils-near';
import { NearChains } from '@requestnetwork/currency';

/**
* processes the transaction to pay a Near request.
Expand All @@ -27,6 +28,7 @@ export async function payNearInputDataRequest(
throw new Error('request.currencyInfo should be a Near network');
}

NearChains.assertChainSupported(request.currencyInfo.network);
validateRequest(request, ExtensionTypes.PAYMENT_NETWORK_ID.NATIVE_TOKEN);

const { paymentReference, paymentAddress } = getRequestPaymentValues(request);
Expand Down
23 changes: 13 additions & 10 deletions packages/payment-processor/src/payment/utils-near.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { BigNumber, BigNumberish, ethers } from 'ethers';
import { Contract } from 'near-api-js';
import { Near, WalletConnection } from 'near-api-js';
import { Contract, Near, WalletConnection } from 'near-api-js';
import {
NearNativeTokenPaymentDetector,
NearConversionNativeTokenPaymentDetector,
NearNativeTokenPaymentDetector,
} from '@requestnetwork/payment-detection';
import { NearChains } from '@requestnetwork/currency';
import { CurrencyTypes } from '@requestnetwork/types';

/**
* Callback arguments for the Near web wallet.
* @member callbackUrl called upon transaction approval
* @member callbackMeta (according to Near docs: `meta` will be attached to the `callbackUrl` as a url search param)
* @member meta (according to Near docs: `meta` will be attached to the `callbackUrl` as a url search param)
*/
export interface INearTransactionCallback {
callbackUrl?: string;
Expand All @@ -26,10 +27,12 @@ export const isValidNearAddress = async (nearNetwork: Near, address: string): Pr
};

export const isNearNetwork = (network?: string): boolean => {
return (
!!network &&
(network === 'near-testnet' || network === 'aurora-testnet' || network === 'aurora')
);
try {
NearChains.assertChainSupported(network);
return true;
} catch {
return false;
}
};

export const isNearAccountSolvent = (
Expand All @@ -52,7 +55,7 @@ const GAS_LIMIT_CONVERSION_TO_NATIVE = GAS_LIMIT.mul(2).toString();

export const processNearPayment = async (
walletConnection: WalletConnection,
network: string,
network: CurrencyTypes.NearChainName,
amount: BigNumberish,
to: string,
paymentReference: string,
Expand Down Expand Up @@ -104,7 +107,7 @@ export const processNearPayment = async (
*/
export const processNearPaymentWithConversion = async (
walletConnection: WalletConnection,
network: string,
network: CurrencyTypes.NearChainName,
amount: BigNumberish,
to: string,
paymentReference: string,
Expand Down
6 changes: 3 additions & 3 deletions packages/types/src/currency-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export type BtcChainName = 'mainnet' | 'testnet';
* List of supported NEAR chains
*/
export type NearChainName =
| 'aurora' // FIXME: aurora should be removed from near chains (it is a mistake)
| 'aurora-testnet' // FIXME: aurora should be removed from near chains (it is a mistake)
| 'near'
| 'aurora'
| 'aurora-testnet'
// | 'near' // TODO: add support for near
| 'near-testnet';

export type ChainName = EvmChainName | BtcChainName | NearChainName;