Skip to content

Commit

Permalink
Merge branch 'any-to-eth-adv-logic' into any-to-eth-smartcontracts
Browse files Browse the repository at this point in the history
  • Loading branch information
vrolland committed Sep 30, 2021
2 parents 4593ade + a52fbad commit 8976c58
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 25 deletions.
Expand Up @@ -3,7 +3,7 @@
## Description

This extension allows the payments and the refunds to be made in ETH on Ethereum or native tokens on EVM blockchains for a request made in others currencies.
The rate is computing at the payment thanks to onchain oracles.
The rate is computed at the payment thanks to onchain oracles.
This Payment Network is quite similar to the [ETH Fee Proxy Contract](./payment-network-eth-fee-proxy-contract-0.1.0.md) extension, with a rate conversion before the payment.

The payment is made through a proxy contract. This proxy contract call the [ETH Fee Proxy Contract](./payment-network-eth-fee-proxy-contract-0.1.0.md) to do the ETH transfer on behalf of the user. The contract ensures a link between an ETH transfer and a request through a `paymentReference`.
Expand Down
@@ -1,10 +1,8 @@
import { ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types';
import Erc20FeeProxyPaymentNetwork from './erc20/fee-proxy-contract';
import { supportedCurrencies } from './chainlink-supported-currencies';
import { supportedCurrencies } from './conversion-supported-currencies';

const CURRENT_VERSION = '0.1.0';
// Default network if the storage data does not give any
const DEFAULT_NETWORK = 'mainnet';

export default class AnyToErc20ProxyPaymentNetwork extends Erc20FeeProxyPaymentNetwork {
public constructor(
Expand Down Expand Up @@ -94,7 +92,7 @@ export default class AnyToErc20ProxyPaymentNetwork extends Erc20FeeProxyPaymentN
paymentAddress: extensionAction.parameters.paymentAddress,
refundAddress: extensionAction.parameters.refundAddress,
salt: extensionAction.parameters.salt,
network: extensionAction.parameters.network || DEFAULT_NETWORK,
network: extensionAction.parameters.network,
acceptedTokens: extensionAction.parameters.acceptedTokens,
maxRateTimespan: extensionAction.parameters.maxRateTimespan,
},
Expand All @@ -103,7 +101,7 @@ export default class AnyToErc20ProxyPaymentNetwork extends Erc20FeeProxyPaymentN
],
values: {
...feePNCreationAction.values,
network: extensionAction.parameters.network || DEFAULT_NETWORK,
network: extensionAction.parameters.network,
acceptedTokens: extensionAction.parameters.acceptedTokens,
maxRateTimespan: extensionAction.parameters.maxRateTimespan,
},
Expand Down
@@ -1,10 +1,8 @@
import { ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types';
import EthereumFeeProxyPaymentNetwork from './ethereum/fee-proxy-contract';
import { supportedCurrencies } from './chainlink-supported-currencies';
import { supportedCurrencies } from './conversion-supported-currencies';

const CURRENT_VERSION = '0.1.0';
// Default network if the storage data does not give any
const DEFAULT_NETWORK = 'mainnet';

export default class AnyToEthProxyPaymentNetwork extends EthereumFeeProxyPaymentNetwork {
public constructor(
Expand Down Expand Up @@ -63,15 +61,15 @@ export default class AnyToEthProxyPaymentNetwork extends EthereumFeeProxyPayment
paymentAddress: extensionAction.parameters.paymentAddress,
refundAddress: extensionAction.parameters.refundAddress,
salt: extensionAction.parameters.salt,
network: extensionAction.parameters.network || DEFAULT_NETWORK,
network: extensionAction.parameters.network,
maxRateTimespan: extensionAction.parameters.maxRateTimespan,
},
timestamp,
},
],
values: {
...feePNCreationAction.values,
network: extensionAction.parameters.network || DEFAULT_NETWORK,
network: extensionAction.parameters.network,
maxRateTimespan: extensionAction.parameters.maxRateTimespan,
},
};
Expand All @@ -90,9 +88,10 @@ export default class AnyToEthProxyPaymentNetwork extends EthereumFeeProxyPayment
const network =
extensionAction.parameters.network || request.extensions[this.extensionId]?.values.network;

// Nothing can be validated if the network has not been given yet
if (!network) {
return;
throw new Error(
`The network must be provided from the creation action or from the extension state`,
);
}

if (!supportedCurrencies[network]) {
Expand Down
Expand Up @@ -9,7 +9,7 @@ import * as TestData from '../../utils/test-data-generator';
const anyToEthProxy = new AnyToEthProxy();

/* eslint-disable @typescript-eslint/no-unused-expressions */
describe('extensions/payment-network/ethereum/any-to-eth-fee-proxy-contract', () => {
describe.only('extensions/payment-network/ethereum/any-to-eth-fee-proxy-contract', () => {
describe('createCreationAction', () => {
it('can create a create action with all parameters', () => {
// 'extension data is wrong'
Expand Down Expand Up @@ -460,7 +460,7 @@ describe('extensions/payment-network/ethereum/any-to-eth-fee-proxy-contract', ()
TestData.payeeRaw.identity,
TestData.arbitraryTimestamp,
);
}).toThrowError(`The extension should be created before receiving any other action`);
}).toThrowError(`The network must be provided from the creation action or from the extension state`);
});

it('cannot applyActionToExtensions of addPaymentAddress without a payee', () => {
Expand Down Expand Up @@ -550,7 +550,7 @@ describe('extensions/payment-network/ethereum/any-to-eth-fee-proxy-contract', ()
TestData.payerRaw.identity,
TestData.arbitraryTimestamp,
);
}).toThrowError(`The extension should be created before receiving any other action`);
}).toThrowError(`The network must be provided from the creation action or from the extension state`);
});

it('cannot applyActionToExtensions of addRefundAddress without a payer', () => {
Expand Down Expand Up @@ -637,7 +637,7 @@ describe('extensions/payment-network/ethereum/any-to-eth-fee-proxy-contract', ()
TestData.payeeRaw.identity,
TestData.arbitraryTimestamp,
);
}).toThrowError(`The extension should be created before receiving any other action`);
}).toThrowError(`The network must be provided from the creation action or from the extension state`);
});

it('cannot applyActionToExtensions of addFee without a payee', () => {
Expand Down
Expand Up @@ -13,6 +13,7 @@ export const refundAddress = '0xf17f52151EbEF6C7334FAD080c5704D77216b732';
export const feeAddress = '0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef';
export const feeAmount = '2000000000000000000';
export const invalidAddress = '0x not and address';
const network = 'mainnet';
// ---------------------------------------------------------------------
export const salt = 'ea3bc7caf64110ca';
// actions
Expand Down Expand Up @@ -46,7 +47,9 @@ export const extensionStateWithPaymentAfterCreation = {
events: [
{
name: ExtensionTypes.PnFeeReferenceBased.ACTION.CREATE,
parameters: {},
parameters: {
network
},
timestamp: arbitraryTimestamp,
},
{
Expand All @@ -61,6 +64,7 @@ export const extensionStateWithPaymentAfterCreation = {
type: ExtensionTypes.TYPE.PAYMENT_NETWORK,
values: {
paymentAddress,
network,
},
version: '0.1.0',
},
Expand All @@ -71,7 +75,9 @@ export const extensionStateWithRefundAfterCreation = {
events: [
{
name: ExtensionTypes.PnFeeReferenceBased.ACTION.CREATE,
parameters: {},
parameters: {
network
},
timestamp: arbitraryTimestamp,
},
{
Expand All @@ -86,6 +92,7 @@ export const extensionStateWithRefundAfterCreation = {
type: ExtensionTypes.TYPE.PAYMENT_NETWORK,
values: {
refundAddress,
network,
},
version: '0.1.0',
},
Expand All @@ -96,7 +103,9 @@ export const extensionStateWithFeeAfterCreation = {
events: [
{
name: ExtensionTypes.PnFeeReferenceBased.ACTION.CREATE,
parameters: {},
parameters: {
network
},
timestamp: arbitraryTimestamp,
},
{
Expand All @@ -113,6 +122,7 @@ export const extensionStateWithFeeAfterCreation = {
values: {
feeAddress,
feeAmount,
network,
},
version: '0.1.0',
},
Expand Down
Expand Up @@ -99,13 +99,17 @@ export const extensionStateCreatedEmpty = {
events: [
{
name: 'create',
parameters: {},
parameters: {
network: 'mainnet',
},
timestamp: arbitraryTimestamp,
},
],
id: ExtensionTypes.ID.PAYMENT_NETWORK_ANY_TO_ETH_PROXY,
type: ExtensionTypes.TYPE.PAYMENT_NETWORK,
values: {},
values: {
network: 'mainnet',
},
version: '0.1.0',
},
};
Expand Down
Expand Up @@ -169,7 +169,7 @@
"currency": {
"type": "string",
"minLength": 2,
"maxLength": 5
"maxLength": 6
},
"deliveryDate": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/extension-types.ts
Expand Up @@ -4,7 +4,7 @@ import * as PnAnyDeclarative from './extensions/pn-any-declarative-types';
import * as PnFeeReferenceBased from './extensions/pn-any-fee-reference-based-types';
import * as PnReferenceBased from './extensions/pn-any-reference-based-types';
import * as PnAnyToErc20 from './extensions/pn-any-to-er20-types';
import * as PnAnyToEth from './extensions/pn-any-to-er20-types';
import * as PnAnyToEth from './extensions/pn-any-to-eth-types';
import * as Identity from './identity-types';
import * as RequestLogic from './request-logic-types';

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/extensions/pn-any-to-er20-types.ts
@@ -1,7 +1,7 @@
import * as Extension from '../extension-types';
import * as PnAnyFees from './pn-any-fee-reference-based-types';

/** Any to ERC20e reference-based payment network extension interface */
/** Any to ERC20 reference-based payment network extension interface */
export interface IAnyToERC20 extends PnAnyFees.IFeeReferenceBased {
createCreationAction: (creationParameters: ICreationParameters) => Extension.IAction;
}
Expand Down

0 comments on commit 8976c58

Please sign in to comment.