Skip to content

Commit 380bfb9

Browse files
authored
feat: merge eth-proxy-contract into eth-input-data (#139)
1 parent f9bff97 commit 380bfb9

File tree

8 files changed

+96
-259
lines changed

8 files changed

+96
-259
lines changed

packages/advanced-logic/specs/payment-network-eth-input-data-0.1.0.md renamed to packages/advanced-logic/specs/payment-network-eth-input-data-0.2.0.md

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ Prerequisite: Having read the advanced logic specification (see [here](./advance
1010
## Description
1111

1212
This extension allows the payments and the refunds to be made in Ether on the Ethereum blockchain.
13-
A payment reference has to be given in input data when making the transfer to link the payment to the request.
13+
A payment reference has to be given when making the transfer to link the payment to the request.
14+
15+
There are two ways to add a payment reference to a transfer:
16+
17+
1. add the reference to the input data of the transfer
18+
2. call the ethereum proxy smart contract (see [Contract](#Contract))
19+
1420
The payment reference is the last 8 bytes of a salted hash of the requestId: `last8Bytes(hash(lowercase(requestId + salt + address)))`:
1521

1622
- `requestId` is the id of the request
@@ -22,13 +28,29 @@ The payment reference is the last 8 bytes of a salted hash of the requestId: `la
2228
As a payment network, this extension allows to deduce a payment `balance` for the request. (see
2329
[Interpretation](#Interpretation))
2430

31+
## Contract
32+
33+
The contract contains one function called `transferWithReference` which takes 2 arguments:
34+
35+
- `to` is the destination address
36+
- `paymentReference` is the reference data used to track the transfer (see `paymentReference`)
37+
38+
The `TransferWithReference` event is emitted when the Ether is transfered. This event contains the same 2 arguments as the `transferWithReference` function plus the `amount` of ethereum sent.
39+
40+
[See smart contract source](https://github.com/RequestNetwork/requestNetwork/blob/master/packages/smart-contracts/src/contracts/EthereumProxy.sol)
41+
42+
| Network | Contract Address |
43+
| ------- | ------------------------------------------ |
44+
| Mainnet | 0x37a8f5f64f2a84f2377481537f04d2a59c9f59b6 |
45+
| Rinkeby | 0x9c6c7817e3679c4b3f9ef9486001eae5aaed25ff |
46+
2547
## Properties
2648

2749
| Property | Type | Description | Requirement |
2850
| ------------------------- | ------ | ---------------------------------------------- | ------------- |
2951
| **id** | String | constant value: "pn-eth-input-data" | **Mandatory** |
3052
| **type** | String | constant value: "paymentNetwork" | **Mandatory** |
31-
| **version** | String | constant value: "0.1.0" | **Mandatory** |
53+
| **version** | String | constant value: "0.2.0" | **Mandatory** |
3254
| **events** | Array | List of the actions performed by the extension | **Mandatory** |
3355
| **values** | Object | | |
3456
| **values.paymentAddress** | String | Ethereum address for the payment | Optional |
@@ -49,7 +71,7 @@ Note: to use the Rinkeby testnet just set the `currency.network` to "rinkeby"
4971
| ----------------------------- | ------ | ----------------------------------- | ------------- |
5072
| **id** | String | Constant value: "pn-eth-input-data" | **Mandatory** |
5173
| **type** | String | Constant value: "paymentNetwork" | **Mandatory** |
52-
| **version** | String | Constant value: "0.1.0" | **Mandatory** |
74+
| **version** | String | Constant value: "0.2.0" | **Mandatory** |
5375
| **parameters** | Object | | |
5476
| **parameters.paymentAddress** | String | Ethereum address for the payment | Optional |
5577
| **parameters.refundAddress** | String | Ethereum address for the refund | Optional |
@@ -82,7 +104,7 @@ A extension state is created with the following properties:
82104
| ------------------------- | -------------------------------------------------------------- |
83105
| **id** | "pn-eth-input-data" |
84106
| **type** | "paymentNetwork" |
85-
| **version** | "0.1.0" |
107+
| **version** | "0.2.0" |
86108
| **values** | |
87109
| **values.paymentAddress** | `paymentAddress` from parameters if given, undefined otherwise |
88110
| **values.refundAddress** | `refundAddress` from parameters if given, undefined otherwise |
@@ -189,6 +211,17 @@ The 'addRefundAddress' event:
189211

190212
## Interpretation
191213

214+
The proxy contract address is determined by the `request.currency.network` (see (table)[#Contract] with proxy contract addresses).
215+
192216
The `balance` starts from `0`.
193217
Any ETH transaction to `paymentAddress` with exactly `last8Bytes(hash(requestId + salt + payment address))` in input data is considered as a payment. The `balance` is increased by the sum of the amounts of the transactions.
218+
Any `TransferWithReference` events emitted from the proxy contract with the following arguments are considered as a payment:
219+
220+
- `to` `===` `paymentAddress`
221+
- `paymentReference` `===` `last8Bytes(hash(lowercase(requestId + salt + payment address)))`
222+
194223
Any ETH transaction to `refundAddress` with exactly `last8Bytes(hash(requestId + salt + refund address))` in input data is considered as a refund. The `balance` is reduced by the sum of the amounts of the transactions.
224+
Any `TransferWithReference` events emitted from the proxy contract with the following arguments are considered as a refund:
225+
226+
- `to` `===` `refundAddress`
227+
- `paymentReference` `===` `last8Bytes(hash(lowercase(requestId + salt + refund address)))`

packages/advanced-logic/specs/payment-network-eth-proxy-contract-0.1.0.md

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

packages/advanced-logic/src/extensions/payment-network/erc20/proxy-contract.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { ExtensionTypes, IdentityTypes, RequestLogicTypes } from '@requestnetwor
22

33
import ReferenceBased from '../reference-based';
44

5+
const CURRENT_VERSION = '0.1.0';
6+
57
const walletAddressValidator = require('wallet-address-validator');
68

79
/**
@@ -43,6 +45,7 @@ function createCreationAction(
4345
return ReferenceBased.createCreationAction(
4446
ExtensionTypes.ID.PAYMENT_NETWORK_ERC20_PROXY_CONTRACT,
4547
creationParameters,
48+
CURRENT_VERSION,
4649
);
4750
}
4851

packages/advanced-logic/src/extensions/payment-network/ethereum/input-data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import ReferenceBased from '../reference-based';
44

55
const walletAddressValidator = require('wallet-address-validator');
66

7+
const CURRENT_VERSION = '0.2.0';
8+
79
/**
810
* Implementation of the payment network to pay in ETH based on input data.
911
* With this extension, one request can have two Ethereum addresses (one for payment and one for refund) and a specific value to give as input data
@@ -43,6 +45,7 @@ function createCreationAction(
4345
return ReferenceBased.createCreationAction(
4446
ExtensionTypes.ID.PAYMENT_NETWORK_ETH_INPUT_DATA,
4547
creationParameters,
48+
CURRENT_VERSION,
4649
);
4750
}
4851

packages/advanced-logic/src/extensions/payment-network/reference-based.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ export default {
1212
createCreationAction,
1313
};
1414

15-
const CURRENT_VERSION = '0.1.0';
16-
1715
// Regex for "at least 16 hexadecimal numbers". Used to validate the salt
1816
const eightHexRegex = /[0-9a-f]{16,}/;
1917

@@ -27,6 +25,7 @@ const eightHexRegex = /[0-9a-f]{16,}/;
2725
function createCreationAction(
2826
extensionId: ExtensionTypes.ID,
2927
creationParameters: ExtensionTypes.PnReferenceBased.ICreationParameters,
28+
version: string,
3029
): ExtensionTypes.IAction {
3130
if (!creationParameters.salt) {
3231
throw Error('salt should not be empty');
@@ -43,7 +42,7 @@ function createCreationAction(
4342
action: ExtensionTypes.PnReferenceBased.ACTION.CREATE,
4443
id: extensionId,
4544
parameters: creationParameters,
46-
version: CURRENT_VERSION,
45+
version,
4746
};
4847
}
4948

@@ -165,6 +164,9 @@ function applyCreation(
165164
extensionAction: ExtensionTypes.IAction,
166165
timestamp: number,
167166
): ExtensionTypes.IState {
167+
if (!extensionAction.version) {
168+
throw Error('version is missing');
169+
}
168170
if (
169171
extensionAction.parameters.paymentAddress &&
170172
!isValidAddress(extensionAction.parameters.paymentAddress)
@@ -196,7 +198,7 @@ function applyCreation(
196198
refundAddress: extensionAction.parameters.refundAddress,
197199
salt: extensionAction.parameters.salt,
198200
},
199-
version: CURRENT_VERSION,
201+
version: extensionAction.version,
200202
};
201203
}
202204

packages/advanced-logic/test/extensions/payment-network/ethereum/input-data.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('extensions/payment-network/ethereum/input-data', () => {
2929
refundAddress: '0x0000000000000000000000000000000000000002',
3030
salt: 'ea3bc7caf64110ca',
3131
},
32-
version: '0.1.0',
32+
version: '0.2.0',
3333
});
3434
});
3535

@@ -45,7 +45,7 @@ describe('extensions/payment-network/ethereum/input-data', () => {
4545
parameters: {
4646
salt: 'ea3bc7caf64110ca',
4747
},
48-
version: '0.1.0',
48+
version: '0.2.0',
4949
});
5050
});
5151

0 commit comments

Comments
 (0)