Skip to content

Commit

Permalink
fix: include feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
bertux committed Feb 24, 2022
1 parent 8af0de6 commit ccc95ed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/integration-test/package.json
Expand Up @@ -30,7 +30,7 @@
"clean": "shx rm -rf dist tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo",
"lint": "eslint \"test/**/*.ts\"",
"test": "run-s test:node test:layers",
"test:scheduled": "run-s test:erc20 test:btc",
"test:scheduled": "run-s test:erc20 test:erc777 test:btc ",
"test:layers": "jest test/layers.test.ts --forceExit",
"test:node": "jest test/node-client.test.ts --forceExit",
"test:erc20": "jest test/scheduled/erc20*.test.ts --forceExit",
Expand Down
18 changes: 10 additions & 8 deletions packages/payment-detection/src/erc777/superfluid-retriever.ts
Expand Up @@ -72,23 +72,25 @@ export class SuperFluidInfoRetriever {
} as FlowUpdatedEvent);
}

const TYPE_BEGIN = 0;
// const TYPE_UPDATE = 1;
const TYPE_END = 2;
for (let index = 1; index < streamEvents.length; index++) {
// FIXME: Handle decreasing flowrate of ongoing payment without closing it
// we have to manage update of flowrate to pay different payment references with the same token
// but we do not manage in the MVP updating flowrate of ongoing payment
// so we should care only about pairs of begin or update event (type 0 or 1) followed by end or update event (type 2 or 1)
// for each update of static flowrate between these 2 chronological sorted events:
// amount paid is the difference of flowrates at the start multiplied by the difference of time
if (
streamEvents[index - 1].type === 2 ||
streamEvents[index].type === 0 ||
streamEvents[index - 1].flowRate < streamEvents[index - 1].oldFlowRate
) {
if (streamEvents[index - 1].type === TYPE_END || streamEvents[index].type === TYPE_BEGIN) {
continue;
}
const diffFlowRate = streamEvents[index - 1].flowRate - streamEvents[index - 1].oldFlowRate;
if (diffFlowRate < 0) {
// FIXME:Handle decreasing flowrate of ongoing payment without closing it
continue;
}
const amount =
(streamEvents[index - 1].flowRate - streamEvents[index - 1].oldFlowRate) *
(streamEvents[index].timestamp - streamEvents[index - 1].timestamp);
diffFlowRate * (streamEvents[index].timestamp - streamEvents[index - 1].timestamp);
paymentEvents.push({
amount: amount.toString(),
name: this.eventName,
Expand Down
Expand Up @@ -3,8 +3,8 @@ import PaymentReferenceCalculator from '../../src/payment-reference-calculator';
import { utils } from 'ethers';
import { PaymentTypes } from '@requestnetwork/types';

describe('api/erc777/superfluid-info-retriever-1request', () => {
describe('on rinkeby', () => {
describe('api/erc777/superfluid-info-retriever', () => {
describe('on untagged requests', () => {
it('should get payment events from SuperFluid via subgraph with 1 request', async () => {
const paymentData = {
reference: '0xf81e1f6b6ff7cd15ab5538b403c8fdf3fed1f254ce6abcddf18941354039c752',
Expand Down Expand Up @@ -44,10 +44,8 @@ describe('api/erc777/superfluid-info-retriever-1request', () => {
expect(transferEvents[0].parameters?.block).toEqual(paymentData.block);
});
});
});

describe('api/erc777/superfluid-info-retriever-2requests', () => {
describe('on rinkeby', () => {
describe('on 2 nested requests', () => {
it('should get payment event from SuperFluid via subgraph with 2 requests', async () => {
const paymentData = {
reference: '0x23b12cbc2c59e39389f3c7cd652c4594a3a7595d7e9af265d07878345a6fe488',
Expand Down Expand Up @@ -80,10 +78,8 @@ describe('api/erc777/superfluid-info-retriever-2requests', () => {
expect(transferEvents[0].parameters?.to).toEqual(paymentData.to);
});
});
});

describe('api/erc777/superfluid-info-retriever-ongoing', () => {
describe('on rinkeby', () => {
describe('on ongoing request', () => {
it('should get payment event from SuperFluid via subgraph with ongoing request', async () => {
const paymentData = {
reference: '0x272b93b983e5435bdba30902066ca3a0839cdb05bd526d648f6b0db79adbd2b5',
Expand Down

0 comments on commit ccc95ed

Please sign in to comment.