Skip to content

Commit

Permalink
fix: use new ERC777 types
Browse files Browse the repository at this point in the history
  • Loading branch information
bertux committed Mar 15, 2022
1 parent 325a2a9 commit d46f0c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ const createMockRequest = ({
creator: { type: IdentityTypes.TYPE.ETHEREUM_ADDRESS, value: '0x2' },
currency: {
network,
type: RequestLogicTypes.CURRENCY.ERC20,
type: RequestLogicTypes.CURRENCY.ERC777,
value: tokenAddress,
},
events: [],
expectedAmount: '320833333333331260',
extensions: {
[ExtensionTypes.ID.PAYMENT_NETWORK_ERC20_PROXY_CONTRACT]: {
[ExtensionTypes.ID.PAYMENT_NETWORK_ERC777_STREAM]: {
events: [],
id: ExtensionTypes.ID.PAYMENT_NETWORK_ERC20_PROXY_CONTRACT,
id: ExtensionTypes.ID.PAYMENT_NETWORK_ERC777_STREAM,
type: ExtensionTypes.TYPE.PAYMENT_NETWORK,
values: {
paymentAddress,
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('ERC777 SuperFluid detection test-suite', () => {
expect(balance.balance).toBe('320833333333331260');
expect(balance.events).toHaveLength(1);
expect(balance.events[0].name).toBe('payment');
const params = balance.events[0].parameters as PaymentTypes.IERC20FeePaymentEventParameters;
const params = balance.events[0].parameters as PaymentTypes.IERC777PaymentEventParameters;
expect(params.to).toBe('0x52e5bcfa46393894afcfe6cd98a6761fa692c594');
expect(balance.events[0].amount).toBe('320833333333331260');
expect(balance.events[0].timestamp).toBe('1642693617');
Expand Down
9 changes: 3 additions & 6 deletions packages/payment-detection/src/erc777/superfluid-detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ import { ReferenceBasedDetector } from '../reference-based-detector';
*/
export class SuperFluidPaymentDetector extends ReferenceBasedDetector<
ExtensionTypes.PnReferenceBased.IReferenceBased,
PaymentTypes.IERC20PaymentEventParameters
PaymentTypes.IERC777PaymentEventParameters
> {
/**
* @param extension The advanced logic payment network extensions
*/
public constructor({ advancedLogic }: { advancedLogic: AdvancedLogicTypes.IAdvancedLogic }) {
super(
PaymentTypes.PAYMENT_NETWORK_ID.ERC20_PROXY_CONTRACT,
advancedLogic.extensions.proxyContractErc20,
);
super(PaymentTypes.PAYMENT_NETWORK_ID.ERC777_STREAM, advancedLogic.extensions.erc777Stream);
}

/**
Expand All @@ -40,7 +37,7 @@ export class SuperFluidPaymentDetector extends ReferenceBasedDetector<
paymentReference: string,
requestCurrency: RequestLogicTypes.ICurrency,
paymentChain: string,
): Promise<PaymentTypes.IPaymentNetworkEvent<PaymentTypes.IERC20PaymentEventParameters>[]> {
): Promise<PaymentTypes.IPaymentNetworkEvent<PaymentTypes.IERC777PaymentEventParameters>[]> {
if (!address) {
return [];
}
Expand Down
4 changes: 2 additions & 2 deletions packages/payment-detection/src/erc777/superfluid-retriever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ export class SuperFluidInfoRetriever {
* into payment events with the parameters expected by extractEvents function
* to compute balance from amounts in ERC20 style transactions
*/
public async getTransferEvents(): Promise<PaymentTypes.ERC20PaymentNetworkEvent[]> {
public async getTransferEvents(): Promise<PaymentTypes.ERC777PaymentNetworkEvent[]> {
const variables = this.getGraphVariables();
const { flow, untagged } = await this.client.GetSuperFluidEvents(variables);
// Chronological sorting of events having payment reference and closing events without payment reference
const streamEvents = flow.concat(untagged).sort((a, b) => a.timestamp - b.timestamp);
const paymentEvents: PaymentTypes.ERC20PaymentNetworkEvent[] = [];
const paymentEvents: PaymentTypes.ERC777PaymentNetworkEvent[] = [];
if (streamEvents.length < 1) {
return paymentEvents;
}
Expand Down

0 comments on commit d46f0c3

Please sign in to comment.