New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@connext/apps

Package Overview
Dependencies
Maintainers
4
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@connext/apps - npm Package Compare versions

Comparing version 7.0.0-alpha.4-experimental to 7.0.0

dist/src/GraphSignedTransferApp/index.d.ts

74

dist/index-iife.js

@@ -324,6 +324,6 @@ this.window = this.window || {};

const { parseUnits, formatEther } = ethers.utils;
const ALLOWED_DISCREPANCY_PCT = 5;
const validateSimpleSwapApp = (params, allowedSwaps, ourRate, responderDecimals) => {
const { responderDeposit, initiatorDeposit, initiatorDepositAssetId, responderDepositAssetId, } = params;
const initiatorDecimals = 18;
const initiatorDepositTokenAddress = utils.getAddressFromAssetId(initiatorDepositAssetId);

@@ -334,12 +334,9 @@ const responderDepositTokenAddress = utils.getAddressFromAssetId(responderDepositAssetId);

}
const calculatedResponderAmountInWeiUnits = utils.calculateExchange(initiatorDeposit, ourRate);
const calculatedResponderDepositNormalized = parseUnits(formatEther(calculatedResponderAmountInWeiUnits), responderDecimals);
const calculatedToActualDiscrepancy = calculatedResponderDepositNormalized
.sub(responderDeposit)
.abs();
const allowedDiscrepancy = calculatedResponderDepositNormalized
const calculatedResponderDeposit = utils.calculateExchangeWad(initiatorDeposit, initiatorDecimals, ourRate, responderDecimals);
const calculatedToActualDiscrepancy = calculatedResponderDeposit.sub(responderDeposit).abs();
const allowedDiscrepancy = calculatedResponderDeposit
.mul(ethers.BigNumber.from(100).sub(ALLOWED_DISCREPANCY_PCT))
.div(100);
if (calculatedToActualDiscrepancy.gt(allowedDiscrepancy)) {
throw new Error(`Responder deposit (${responderDeposit.toString()}) is greater than our expected deposit (${calculatedResponderDepositNormalized.toString()}) based on our swap rate ${ourRate} by more than ${ALLOWED_DISCREPANCY_PCT}% (discrepancy: ${calculatedToActualDiscrepancy.toString()})`);
throw new Error(`Responder deposit (${responderDeposit.toString()}) is greater than our expected deposit (${calculatedResponderDeposit.toString()}) based on our swap rate ${ourRate} by more than ${ALLOWED_DISCREPANCY_PCT}% (discrepancy: ${calculatedToActualDiscrepancy.toString()})`);
}

@@ -352,5 +349,23 @@ };

const { Zero: Zero$8 } = ethers.constants;
const GraphSignedTransferAppRegistryInfo = {
allowNodeInstall: true,
name: types.GraphSignedTransferAppName,
outcomeType: types.OutcomeType.SINGLE_ASSET_TWO_PARTY_COIN_TRANSFER,
stateEncoding: types.GraphSignedTransferAppStateEncoding,
actionEncoding: types.GraphSignedTransferAppActionEncoding,
};
const GRAPH_SIGNED_TRANSFER_STATE_TIMEOUT = Zero$8;
const validateGraphSignedTransferApp = (params) => validateSignedTransferApp(params);
const proposeGraphSignedTransferMiddleware = (cxt) => {
const { params } = cxt;
return validateGraphSignedTransferApp(params);
};
const AppRegistry = [
SimpleLinkedTransferAppRegistryInfo,
SimpleSignedTransferAppRegistryInfo,
GraphSignedTransferAppRegistryInfo,
SimpleTwoPartySwapAppRegistryInfo,

@@ -375,14 +390,11 @@ WithdrawAppRegistryInfo,

};
const generateValidationMiddleware = async (network, supportedTokenAddresses) => {
if (!network.provider) {
throw new Error(`Validation middleware needs access to a provider`);
}
const generateValidationMiddleware = async (networkContexts, supportedTokenAddresses) => {
const validationMiddleware = async (protocol, middlewareContext) => {
switch (protocol) {
case types.ProtocolNames.propose: {
await proposeMiddleware(network, middlewareContext, supportedTokenAddresses);
await proposeMiddleware(networkContexts, middlewareContext, supportedTokenAddresses);
break;
}
case types.ProtocolNames.uninstall: {
await uninstallMiddleware(network, middlewareContext);
await uninstallMiddleware(networkContexts, middlewareContext);
break;

@@ -401,8 +413,9 @@ }

};
const uninstallMiddleware = async (network, middlewareContext) => {
const { appInstance } = middlewareContext;
const uninstallMiddleware = async (networkContexts, middlewareContext) => {
const { appInstance, stateChannel } = middlewareContext;
const { contractAddresses, provider } = networkContexts[stateChannel.chainId];
const appDef = appInstance.appDefinition;
switch (appDef) {
case network.contractAddresses.DepositApp: {
await uninstallDepositMiddleware(middlewareContext, network.provider);
case contractAddresses.DepositApp: {
await uninstallDepositMiddleware(middlewareContext, provider);
break;

@@ -415,12 +428,17 @@ }

};
const proposeMiddleware = async (network, middlewareContext, supportedTokenAddresses) => {
const { contractAddresses } = network;
const { proposal } = middlewareContext;
sharedProposalMiddleware(middlewareContext, contractAddresses, supportedTokenAddresses);
const proposeMiddleware = async (networkContexts, middlewareContext, supportedTokenAddresses) => {
const { proposal, stateChannel } = middlewareContext;
const { contractAddresses, provider } = networkContexts[stateChannel.chainId];
const supportedTokensForChainId = supportedTokenAddresses[stateChannel.chainId];
sharedProposalMiddleware(middlewareContext, contractAddresses, supportedTokensForChainId);
const appDef = proposal.appDefinition;
switch (appDef) {
case contractAddresses.DepositApp: {
await proposeDepositMiddleware(middlewareContext, network.provider);
await proposeDepositMiddleware(middlewareContext, provider);
break;
}
case contractAddresses.GraphSignedTransferApp: {
proposeGraphSignedTransferMiddleware(middlewareContext);
break;
}
case contractAddresses.SimpleTwoPartySwapApp: {

@@ -438,3 +456,3 @@ break;

case contractAddresses.HashLockTransferApp: {
await proposeHashLockTransferMiddleware(middlewareContext, network.provider);
await proposeHashLockTransferMiddleware(middlewareContext, provider);
break;

@@ -452,4 +470,4 @@ }

const { Zero: Zero$8 } = ethers.constants;
const TRANSFER_TIMEOUT = Zero$8;
const { Zero: Zero$9 } = ethers.constants;
const TRANSFER_TIMEOUT = Zero$9;

@@ -460,2 +478,4 @@ exports.AppRegistry = AppRegistry;

exports.DepositAppRegistryInfo = DepositAppRegistryInfo;
exports.GRAPH_SIGNED_TRANSFER_STATE_TIMEOUT = GRAPH_SIGNED_TRANSFER_STATE_TIMEOUT;
exports.GraphSignedTransferAppRegistryInfo = GraphSignedTransferAppRegistryInfo;
exports.HASHLOCK_TRANSFER_STATE_TIMEOUT = HASHLOCK_TRANSFER_STATE_TIMEOUT;

@@ -478,2 +498,3 @@ exports.HashLockTransferAppRegistryInfo = HashLockTransferAppRegistryInfo;

exports.proposeDepositMiddleware = proposeDepositMiddleware;
exports.proposeGraphSignedTransferMiddleware = proposeGraphSignedTransferMiddleware;
exports.proposeHashLockTransferMiddleware = proposeHashLockTransferMiddleware;

@@ -488,2 +509,3 @@ exports.proposeLinkedTransferMiddleware = proposeLinkedTransferMiddleware;

exports.validateDepositApp = validateDepositApp;
exports.validateGraphSignedTransferApp = validateGraphSignedTransferApp;
exports.validateHashLockTransferApp = validateHashLockTransferApp;

@@ -490,0 +512,0 @@ exports.validateSignedTransferApp = validateSignedTransferApp;

import { constants, Contract, utils, BigNumber } from 'ethers';
import { DepositAppName, OutcomeType, DepositAppStateEncoding, CONVENTION_FOR_ETH_ASSET_ID, Contract as Contract$1, ProtocolRoles, HashLockTransferAppName, HashLockTransferAppActionEncoding, HashLockTransferAppStateEncoding, SimpleLinkedTransferAppActionEncoding, SimpleLinkedTransferAppName, SimpleLinkedTransferAppStateEncoding, SimpleSignedTransferAppName, SimpleSignedTransferAppStateEncoding, SimpleSignedTransferAppActionEncoding, WithdrawAppName, WithdrawAppStateEncoding, WithdrawAppActionEncoding, singleAssetSinglePartyCoinTransferEncoding, singleAssetTwoPartyCoinTransferInterpreterParamsEncoding, MultisigOperation, SimpleTwoPartySwapAppName, SimpleSwapAppStateEncoding, ProtocolNames } from '@connext/types';
import { toBN, getAddressFromAssetId, stringify, getSignerAddressFromPublicIdentifier, bigNumberifyJson, recoverAddressFromChannelMessage, calculateExchange } from '@connext/utils';
import { DepositAppName, OutcomeType, DepositAppStateEncoding, CONVENTION_FOR_ETH_ASSET_ID, Contract as Contract$1, ProtocolRoles, HashLockTransferAppName, HashLockTransferAppActionEncoding, HashLockTransferAppStateEncoding, SimpleLinkedTransferAppActionEncoding, SimpleLinkedTransferAppName, SimpleLinkedTransferAppStateEncoding, SimpleSignedTransferAppName, SimpleSignedTransferAppStateEncoding, SimpleSignedTransferAppActionEncoding, WithdrawAppName, WithdrawAppStateEncoding, WithdrawAppActionEncoding, singleAssetSinglePartyCoinTransferEncoding, singleAssetTwoPartyCoinTransferInterpreterParamsEncoding, MultisigOperation, SimpleTwoPartySwapAppName, SimpleSwapAppStateEncoding, GraphSignedTransferAppName, GraphSignedTransferAppStateEncoding, GraphSignedTransferAppActionEncoding, ProtocolNames } from '@connext/types';
import { toBN, getAddressFromAssetId, stringify, getSignerAddressFromPublicIdentifier, bigNumberifyJson, recoverAddressFromChannelMessage, calculateExchangeWad } from '@connext/utils';
import { ERC20, MinimumViableMultisig, MultisigCommitment, ConditionalTransactionDelegateTarget } from '@connext/contracts';

@@ -325,6 +325,6 @@

const { parseUnits, formatEther } = utils;
const ALLOWED_DISCREPANCY_PCT = 5;
const validateSimpleSwapApp = (params, allowedSwaps, ourRate, responderDecimals) => {
const { responderDeposit, initiatorDeposit, initiatorDepositAssetId, responderDepositAssetId, } = params;
const initiatorDecimals = 18;
const initiatorDepositTokenAddress = getAddressFromAssetId(initiatorDepositAssetId);

@@ -335,12 +335,9 @@ const responderDepositTokenAddress = getAddressFromAssetId(responderDepositAssetId);

}
const calculatedResponderAmountInWeiUnits = calculateExchange(initiatorDeposit, ourRate);
const calculatedResponderDepositNormalized = parseUnits(formatEther(calculatedResponderAmountInWeiUnits), responderDecimals);
const calculatedToActualDiscrepancy = calculatedResponderDepositNormalized
.sub(responderDeposit)
.abs();
const allowedDiscrepancy = calculatedResponderDepositNormalized
const calculatedResponderDeposit = calculateExchangeWad(initiatorDeposit, initiatorDecimals, ourRate, responderDecimals);
const calculatedToActualDiscrepancy = calculatedResponderDeposit.sub(responderDeposit).abs();
const allowedDiscrepancy = calculatedResponderDeposit
.mul(BigNumber.from(100).sub(ALLOWED_DISCREPANCY_PCT))
.div(100);
if (calculatedToActualDiscrepancy.gt(allowedDiscrepancy)) {
throw new Error(`Responder deposit (${responderDeposit.toString()}) is greater than our expected deposit (${calculatedResponderDepositNormalized.toString()}) based on our swap rate ${ourRate} by more than ${ALLOWED_DISCREPANCY_PCT}% (discrepancy: ${calculatedToActualDiscrepancy.toString()})`);
throw new Error(`Responder deposit (${responderDeposit.toString()}) is greater than our expected deposit (${calculatedResponderDeposit.toString()}) based on our swap rate ${ourRate} by more than ${ALLOWED_DISCREPANCY_PCT}% (discrepancy: ${calculatedToActualDiscrepancy.toString()})`);
}

@@ -353,5 +350,23 @@ };

const { Zero: Zero$8 } = constants;
const GraphSignedTransferAppRegistryInfo = {
allowNodeInstall: true,
name: GraphSignedTransferAppName,
outcomeType: OutcomeType.SINGLE_ASSET_TWO_PARTY_COIN_TRANSFER,
stateEncoding: GraphSignedTransferAppStateEncoding,
actionEncoding: GraphSignedTransferAppActionEncoding,
};
const GRAPH_SIGNED_TRANSFER_STATE_TIMEOUT = Zero$8;
const validateGraphSignedTransferApp = (params) => validateSignedTransferApp(params);
const proposeGraphSignedTransferMiddleware = (cxt) => {
const { params } = cxt;
return validateGraphSignedTransferApp(params);
};
const AppRegistry = [
SimpleLinkedTransferAppRegistryInfo,
SimpleSignedTransferAppRegistryInfo,
GraphSignedTransferAppRegistryInfo,
SimpleTwoPartySwapAppRegistryInfo,

@@ -376,14 +391,11 @@ WithdrawAppRegistryInfo,

};
const generateValidationMiddleware = async (network, supportedTokenAddresses) => {
if (!network.provider) {
throw new Error(`Validation middleware needs access to a provider`);
}
const generateValidationMiddleware = async (networkContexts, supportedTokenAddresses) => {
const validationMiddleware = async (protocol, middlewareContext) => {
switch (protocol) {
case ProtocolNames.propose: {
await proposeMiddleware(network, middlewareContext, supportedTokenAddresses);
await proposeMiddleware(networkContexts, middlewareContext, supportedTokenAddresses);
break;
}
case ProtocolNames.uninstall: {
await uninstallMiddleware(network, middlewareContext);
await uninstallMiddleware(networkContexts, middlewareContext);
break;

@@ -402,8 +414,9 @@ }

};
const uninstallMiddleware = async (network, middlewareContext) => {
const { appInstance } = middlewareContext;
const uninstallMiddleware = async (networkContexts, middlewareContext) => {
const { appInstance, stateChannel } = middlewareContext;
const { contractAddresses, provider } = networkContexts[stateChannel.chainId];
const appDef = appInstance.appDefinition;
switch (appDef) {
case network.contractAddresses.DepositApp: {
await uninstallDepositMiddleware(middlewareContext, network.provider);
case contractAddresses.DepositApp: {
await uninstallDepositMiddleware(middlewareContext, provider);
break;

@@ -416,12 +429,17 @@ }

};
const proposeMiddleware = async (network, middlewareContext, supportedTokenAddresses) => {
const { contractAddresses } = network;
const { proposal } = middlewareContext;
sharedProposalMiddleware(middlewareContext, contractAddresses, supportedTokenAddresses);
const proposeMiddleware = async (networkContexts, middlewareContext, supportedTokenAddresses) => {
const { proposal, stateChannel } = middlewareContext;
const { contractAddresses, provider } = networkContexts[stateChannel.chainId];
const supportedTokensForChainId = supportedTokenAddresses[stateChannel.chainId];
sharedProposalMiddleware(middlewareContext, contractAddresses, supportedTokensForChainId);
const appDef = proposal.appDefinition;
switch (appDef) {
case contractAddresses.DepositApp: {
await proposeDepositMiddleware(middlewareContext, network.provider);
await proposeDepositMiddleware(middlewareContext, provider);
break;
}
case contractAddresses.GraphSignedTransferApp: {
proposeGraphSignedTransferMiddleware(middlewareContext);
break;
}
case contractAddresses.SimpleTwoPartySwapApp: {

@@ -439,3 +457,3 @@ break;

case contractAddresses.HashLockTransferApp: {
await proposeHashLockTransferMiddleware(middlewareContext, network.provider);
await proposeHashLockTransferMiddleware(middlewareContext, provider);
break;

@@ -453,5 +471,5 @@ }

const { Zero: Zero$8 } = constants;
const TRANSFER_TIMEOUT = Zero$8;
const { Zero: Zero$9 } = constants;
const TRANSFER_TIMEOUT = Zero$9;
export { AppRegistry, DEFAULT_APP_TIMEOUT, DEPOSIT_STATE_TIMEOUT, DepositAppRegistryInfo, HASHLOCK_TRANSFER_STATE_TIMEOUT, HashLockTransferAppRegistryInfo, LINKED_TRANSFER_STATE_TIMEOUT, MINIMUM_APP_TIMEOUT, SIGNED_TRANSFER_STATE_TIMEOUT, SWAP_STATE_TIMEOUT, SimpleLinkedTransferAppRegistryInfo, SimpleSignedTransferAppRegistryInfo, SimpleTwoPartySwapAppRegistryInfo, TRANSFER_TIMEOUT, WITHDRAW_STATE_TIMEOUT, WithdrawAppRegistryInfo, WithdrawCommitment, baseCoinTransferValidation, commonAppProposalValidation, generateValidationMiddleware, proposeDepositMiddleware, proposeHashLockTransferMiddleware, proposeLinkedTransferMiddleware, proposeSignedTransferMiddleware, proposeSwapMiddleware, proposeWithdrawMiddleware, sharedProposalMiddleware, unidirectionalCoinTransferValidation, uninstallDepositMiddleware, validateDepositApp, validateHashLockTransferApp, validateSignedTransferApp, validateSimpleLinkedTransferApp, validateSimpleSwapApp, validateWithdrawApp };
export { AppRegistry, DEFAULT_APP_TIMEOUT, DEPOSIT_STATE_TIMEOUT, DepositAppRegistryInfo, GRAPH_SIGNED_TRANSFER_STATE_TIMEOUT, GraphSignedTransferAppRegistryInfo, HASHLOCK_TRANSFER_STATE_TIMEOUT, HashLockTransferAppRegistryInfo, LINKED_TRANSFER_STATE_TIMEOUT, MINIMUM_APP_TIMEOUT, SIGNED_TRANSFER_STATE_TIMEOUT, SWAP_STATE_TIMEOUT, SimpleLinkedTransferAppRegistryInfo, SimpleSignedTransferAppRegistryInfo, SimpleTwoPartySwapAppRegistryInfo, TRANSFER_TIMEOUT, WITHDRAW_STATE_TIMEOUT, WithdrawAppRegistryInfo, WithdrawCommitment, baseCoinTransferValidation, commonAppProposalValidation, generateValidationMiddleware, proposeDepositMiddleware, proposeGraphSignedTransferMiddleware, proposeHashLockTransferMiddleware, proposeLinkedTransferMiddleware, proposeSignedTransferMiddleware, proposeSwapMiddleware, proposeWithdrawMiddleware, sharedProposalMiddleware, unidirectionalCoinTransferValidation, uninstallDepositMiddleware, validateDepositApp, validateGraphSignedTransferApp, validateHashLockTransferApp, validateSignedTransferApp, validateSimpleLinkedTransferApp, validateSimpleSwapApp, validateWithdrawApp };

@@ -329,6 +329,6 @@ 'use strict';

const { parseUnits, formatEther } = ethers.utils;
const ALLOWED_DISCREPANCY_PCT = 5;
const validateSimpleSwapApp = (params, allowedSwaps, ourRate, responderDecimals) => {
const { responderDeposit, initiatorDeposit, initiatorDepositAssetId, responderDepositAssetId, } = params;
const initiatorDecimals = 18;
const initiatorDepositTokenAddress = utils.getAddressFromAssetId(initiatorDepositAssetId);

@@ -339,12 +339,9 @@ const responderDepositTokenAddress = utils.getAddressFromAssetId(responderDepositAssetId);

}
const calculatedResponderAmountInWeiUnits = utils.calculateExchange(initiatorDeposit, ourRate);
const calculatedResponderDepositNormalized = parseUnits(formatEther(calculatedResponderAmountInWeiUnits), responderDecimals);
const calculatedToActualDiscrepancy = calculatedResponderDepositNormalized
.sub(responderDeposit)
.abs();
const allowedDiscrepancy = calculatedResponderDepositNormalized
const calculatedResponderDeposit = utils.calculateExchangeWad(initiatorDeposit, initiatorDecimals, ourRate, responderDecimals);
const calculatedToActualDiscrepancy = calculatedResponderDeposit.sub(responderDeposit).abs();
const allowedDiscrepancy = calculatedResponderDeposit
.mul(ethers.BigNumber.from(100).sub(ALLOWED_DISCREPANCY_PCT))
.div(100);
if (calculatedToActualDiscrepancy.gt(allowedDiscrepancy)) {
throw new Error(`Responder deposit (${responderDeposit.toString()}) is greater than our expected deposit (${calculatedResponderDepositNormalized.toString()}) based on our swap rate ${ourRate} by more than ${ALLOWED_DISCREPANCY_PCT}% (discrepancy: ${calculatedToActualDiscrepancy.toString()})`);
throw new Error(`Responder deposit (${responderDeposit.toString()}) is greater than our expected deposit (${calculatedResponderDeposit.toString()}) based on our swap rate ${ourRate} by more than ${ALLOWED_DISCREPANCY_PCT}% (discrepancy: ${calculatedToActualDiscrepancy.toString()})`);
}

@@ -357,5 +354,23 @@ };

const { Zero: Zero$8 } = ethers.constants;
const GraphSignedTransferAppRegistryInfo = {
allowNodeInstall: true,
name: types.GraphSignedTransferAppName,
outcomeType: types.OutcomeType.SINGLE_ASSET_TWO_PARTY_COIN_TRANSFER,
stateEncoding: types.GraphSignedTransferAppStateEncoding,
actionEncoding: types.GraphSignedTransferAppActionEncoding,
};
const GRAPH_SIGNED_TRANSFER_STATE_TIMEOUT = Zero$8;
const validateGraphSignedTransferApp = (params) => validateSignedTransferApp(params);
const proposeGraphSignedTransferMiddleware = (cxt) => {
const { params } = cxt;
return validateGraphSignedTransferApp(params);
};
const AppRegistry = [
SimpleLinkedTransferAppRegistryInfo,
SimpleSignedTransferAppRegistryInfo,
GraphSignedTransferAppRegistryInfo,
SimpleTwoPartySwapAppRegistryInfo,

@@ -380,14 +395,11 @@ WithdrawAppRegistryInfo,

};
const generateValidationMiddleware = async (network, supportedTokenAddresses) => {
if (!network.provider) {
throw new Error(`Validation middleware needs access to a provider`);
}
const generateValidationMiddleware = async (networkContexts, supportedTokenAddresses) => {
const validationMiddleware = async (protocol, middlewareContext) => {
switch (protocol) {
case types.ProtocolNames.propose: {
await proposeMiddleware(network, middlewareContext, supportedTokenAddresses);
await proposeMiddleware(networkContexts, middlewareContext, supportedTokenAddresses);
break;
}
case types.ProtocolNames.uninstall: {
await uninstallMiddleware(network, middlewareContext);
await uninstallMiddleware(networkContexts, middlewareContext);
break;

@@ -406,8 +418,9 @@ }

};
const uninstallMiddleware = async (network, middlewareContext) => {
const { appInstance } = middlewareContext;
const uninstallMiddleware = async (networkContexts, middlewareContext) => {
const { appInstance, stateChannel } = middlewareContext;
const { contractAddresses, provider } = networkContexts[stateChannel.chainId];
const appDef = appInstance.appDefinition;
switch (appDef) {
case network.contractAddresses.DepositApp: {
await uninstallDepositMiddleware(middlewareContext, network.provider);
case contractAddresses.DepositApp: {
await uninstallDepositMiddleware(middlewareContext, provider);
break;

@@ -420,12 +433,17 @@ }

};
const proposeMiddleware = async (network, middlewareContext, supportedTokenAddresses) => {
const { contractAddresses } = network;
const { proposal } = middlewareContext;
sharedProposalMiddleware(middlewareContext, contractAddresses, supportedTokenAddresses);
const proposeMiddleware = async (networkContexts, middlewareContext, supportedTokenAddresses) => {
const { proposal, stateChannel } = middlewareContext;
const { contractAddresses, provider } = networkContexts[stateChannel.chainId];
const supportedTokensForChainId = supportedTokenAddresses[stateChannel.chainId];
sharedProposalMiddleware(middlewareContext, contractAddresses, supportedTokensForChainId);
const appDef = proposal.appDefinition;
switch (appDef) {
case contractAddresses.DepositApp: {
await proposeDepositMiddleware(middlewareContext, network.provider);
await proposeDepositMiddleware(middlewareContext, provider);
break;
}
case contractAddresses.GraphSignedTransferApp: {
proposeGraphSignedTransferMiddleware(middlewareContext);
break;
}
case contractAddresses.SimpleTwoPartySwapApp: {

@@ -443,3 +461,3 @@ break;

case contractAddresses.HashLockTransferApp: {
await proposeHashLockTransferMiddleware(middlewareContext, network.provider);
await proposeHashLockTransferMiddleware(middlewareContext, provider);
break;

@@ -457,4 +475,4 @@ }

const { Zero: Zero$8 } = ethers.constants;
const TRANSFER_TIMEOUT = Zero$8;
const { Zero: Zero$9 } = ethers.constants;
const TRANSFER_TIMEOUT = Zero$9;

@@ -465,2 +483,4 @@ exports.AppRegistry = AppRegistry;

exports.DepositAppRegistryInfo = DepositAppRegistryInfo;
exports.GRAPH_SIGNED_TRANSFER_STATE_TIMEOUT = GRAPH_SIGNED_TRANSFER_STATE_TIMEOUT;
exports.GraphSignedTransferAppRegistryInfo = GraphSignedTransferAppRegistryInfo;
exports.HASHLOCK_TRANSFER_STATE_TIMEOUT = HASHLOCK_TRANSFER_STATE_TIMEOUT;

@@ -483,2 +503,3 @@ exports.HashLockTransferAppRegistryInfo = HashLockTransferAppRegistryInfo;

exports.proposeDepositMiddleware = proposeDepositMiddleware;
exports.proposeGraphSignedTransferMiddleware = proposeGraphSignedTransferMiddleware;
exports.proposeHashLockTransferMiddleware = proposeHashLockTransferMiddleware;

@@ -493,2 +514,3 @@ exports.proposeLinkedTransferMiddleware = proposeLinkedTransferMiddleware;

exports.validateDepositApp = validateDepositApp;
exports.validateGraphSignedTransferApp = validateGraphSignedTransferApp;
exports.validateHashLockTransferApp = validateHashLockTransferApp;

@@ -495,0 +517,0 @@ exports.validateSignedTransferApp = validateSignedTransferApp;

@@ -9,4 +9,5 @@ export declare const TRANSFER_TIMEOUT: import("ethers").BigNumber;

export * from "./SimpleSignedTransferApp";
export * from "./GraphSignedTransferApp";
export * from "./SimpleTwoPartySwapApp";
export * from "./WithdrawApp";
//# sourceMappingURL=index.d.ts.map

@@ -11,4 +11,5 @@ import { constants } from "ethers";

export * from "./SimpleSignedTransferApp";
export * from "./GraphSignedTransferApp";
export * from "./SimpleTwoPartySwapApp";
export * from "./WithdrawApp";
//# sourceMappingURL=index.js.map

@@ -1,4 +0,6 @@

import { Address, ContractAddresses, NetworkContext, ProposeMiddlewareContext, ValidationMiddleware } from "@connext/types";
import { Address, ContractAddresses, NetworkContexts, ProposeMiddlewareContext, ValidationMiddleware } from "@connext/types";
export declare const sharedProposalMiddleware: (cxt: ProposeMiddlewareContext, contractAddresses: ContractAddresses, supportedTokenAddresses: Address[]) => void;
export declare const generateValidationMiddleware: (network: NetworkContext, supportedTokenAddresses: Address[]) => Promise<ValidationMiddleware>;
export declare const generateValidationMiddleware: (networkContexts: NetworkContexts, supportedTokenAddresses: {
[chainId: number]: string[];
}) => Promise<ValidationMiddleware>;
//# sourceMappingURL=middleware.d.ts.map

@@ -11,2 +11,3 @@ import { ProtocolNames, } from "@connext/types";

import { AppRegistry } from "./registry";
import { proposeGraphSignedTransferMiddleware } from "./GraphSignedTransferApp";
const getNameFromAddress = (contractAddress, appDefinition) => {

@@ -25,14 +26,11 @@ const [name] = Object.entries(contractAddress).find(([name, addr]) => addr === appDefinition) || [];

};
export const generateValidationMiddleware = async (network, supportedTokenAddresses) => {
if (!network.provider) {
throw new Error(`Validation middleware needs access to a provider`);
}
export const generateValidationMiddleware = async (networkContexts, supportedTokenAddresses) => {
const validationMiddleware = async (protocol, middlewareContext) => {
switch (protocol) {
case ProtocolNames.propose: {
await proposeMiddleware(network, middlewareContext, supportedTokenAddresses);
await proposeMiddleware(networkContexts, middlewareContext, supportedTokenAddresses);
break;
}
case ProtocolNames.uninstall: {
await uninstallMiddleware(network, middlewareContext);
await uninstallMiddleware(networkContexts, middlewareContext);
break;

@@ -51,8 +49,9 @@ }

};
const uninstallMiddleware = async (network, middlewareContext) => {
const { appInstance } = middlewareContext;
const uninstallMiddleware = async (networkContexts, middlewareContext) => {
const { appInstance, stateChannel } = middlewareContext;
const { contractAddresses, provider } = networkContexts[stateChannel.chainId];
const appDef = appInstance.appDefinition;
switch (appDef) {
case network.contractAddresses.DepositApp: {
await uninstallDepositMiddleware(middlewareContext, network.provider);
case contractAddresses.DepositApp: {
await uninstallDepositMiddleware(middlewareContext, provider);
break;

@@ -65,12 +64,17 @@ }

};
const proposeMiddleware = async (network, middlewareContext, supportedTokenAddresses) => {
const { contractAddresses } = network;
const { proposal } = middlewareContext;
sharedProposalMiddleware(middlewareContext, contractAddresses, supportedTokenAddresses);
const proposeMiddleware = async (networkContexts, middlewareContext, supportedTokenAddresses) => {
const { proposal, stateChannel } = middlewareContext;
const { contractAddresses, provider } = networkContexts[stateChannel.chainId];
const supportedTokensForChainId = supportedTokenAddresses[stateChannel.chainId];
sharedProposalMiddleware(middlewareContext, contractAddresses, supportedTokensForChainId);
const appDef = proposal.appDefinition;
switch (appDef) {
case contractAddresses.DepositApp: {
await proposeDepositMiddleware(middlewareContext, network.provider);
await proposeDepositMiddleware(middlewareContext, provider);
break;
}
case contractAddresses.GraphSignedTransferApp: {
proposeGraphSignedTransferMiddleware(middlewareContext);
break;
}
case contractAddresses.SimpleTwoPartySwapApp: {

@@ -89,3 +93,3 @@ proposeSwapMiddleware(middlewareContext);

case contractAddresses.HashLockTransferApp: {
await proposeHashLockTransferMiddleware(middlewareContext, network.provider);
await proposeHashLockTransferMiddleware(middlewareContext, provider);
break;

@@ -92,0 +96,0 @@ }

@@ -5,2 +5,3 @@ import { DepositAppRegistryInfo } from "./DepositApp";

import { SimpleSignedTransferAppRegistryInfo } from "./SimpleSignedTransferApp";
import { GraphSignedTransferAppRegistryInfo } from "./GraphSignedTransferApp";
import { SimpleTwoPartySwapAppRegistryInfo } from "./SimpleTwoPartySwapApp";

@@ -11,2 +12,3 @@ import { WithdrawAppRegistryInfo } from "./WithdrawApp";

SimpleSignedTransferAppRegistryInfo,
GraphSignedTransferAppRegistryInfo,
SimpleTwoPartySwapAppRegistryInfo,

@@ -13,0 +15,0 @@ WithdrawAppRegistryInfo,

@@ -1,3 +0,3 @@

import { SwapRate, ProtocolParams } from "@connext/types";
export declare const validateSimpleSwapApp: (params: ProtocolParams.Propose, allowedSwaps: SwapRate[], ourRate: string, responderDecimals: number) => void;
import { AllowedSwap, ProtocolParams } from "@connext/types";
export declare const validateSimpleSwapApp: (params: ProtocolParams.Propose, allowedSwaps: AllowedSwap[], ourRate: string, responderDecimals: number) => void;
//# sourceMappingURL=validation.d.ts.map

@@ -1,7 +0,7 @@

import { calculateExchange, getAddressFromAssetId, stringify } from "@connext/utils";
import { BigNumber, utils } from "ethers";
const { parseUnits, formatEther } = utils;
import { calculateExchangeWad, getAddressFromAssetId, stringify } from "@connext/utils";
import { BigNumber } from "ethers";
const ALLOWED_DISCREPANCY_PCT = 5;
export const validateSimpleSwapApp = (params, allowedSwaps, ourRate, responderDecimals) => {
const { responderDeposit, initiatorDeposit, initiatorDepositAssetId, responderDepositAssetId, } = params;
const initiatorDecimals = 18;
const initiatorDepositTokenAddress = getAddressFromAssetId(initiatorDepositAssetId);

@@ -12,14 +12,11 @@ const responderDepositTokenAddress = getAddressFromAssetId(responderDepositAssetId);

}
const calculatedResponderAmountInWeiUnits = calculateExchange(initiatorDeposit, ourRate);
const calculatedResponderDepositNormalized = parseUnits(formatEther(calculatedResponderAmountInWeiUnits), responderDecimals);
const calculatedToActualDiscrepancy = calculatedResponderDepositNormalized
.sub(responderDeposit)
.abs();
const allowedDiscrepancy = calculatedResponderDepositNormalized
const calculatedResponderDeposit = calculateExchangeWad(initiatorDeposit, initiatorDecimals, ourRate, responderDecimals);
const calculatedToActualDiscrepancy = calculatedResponderDeposit.sub(responderDeposit).abs();
const allowedDiscrepancy = calculatedResponderDeposit
.mul(BigNumber.from(100).sub(ALLOWED_DISCREPANCY_PCT))
.div(100);
if (calculatedToActualDiscrepancy.gt(allowedDiscrepancy)) {
throw new Error(`Responder deposit (${responderDeposit.toString()}) is greater than our expected deposit (${calculatedResponderDepositNormalized.toString()}) based on our swap rate ${ourRate} by more than ${ALLOWED_DISCREPANCY_PCT}% (discrepancy: ${calculatedToActualDiscrepancy.toString()})`);
throw new Error(`Responder deposit (${responderDeposit.toString()}) is greater than our expected deposit (${calculatedResponderDeposit.toString()}) based on our swap rate ${ourRate} by more than ${ALLOWED_DISCREPANCY_PCT}% (discrepancy: ${calculatedToActualDiscrepancy.toString()})`);
}
};
//# sourceMappingURL=validation.js.map
{
"name": "@connext/apps",
"version": "7.0.0-alpha.4-experimental",
"version": "7.0.0",
"description": "Connext Counterfactual Apps",

@@ -14,3 +14,3 @@ "main": "dist/index.js",

"scripts": {
"build": "./node_modules/.bin/tsc -b . && ./node_modules/.bin/rollup -c",
"build": "../../node_modules/.bin/tsc -b . && ../../node_modules/.bin/rollup -c",
"lint": "../../node_modules/.bin/eslint -c '../../.eslintrc.js' --fix 'src/**/*'",

@@ -22,11 +22,11 @@ "test": "echo \"Error: no test specified\" && exit 1",

"devDependencies": {
"@connext/contracts": "3.2.3",
"@connext/utils": "7.0.0-alpha.4-experimental",
"@connext/types": "7.0.0-alpha.4-experimental",
"ethers": "5.0.2",
"rollup": "2.18.0",
"@connext/contracts": "3.4.1",
"@connext/types": "7.0.0",
"@connext/utils": "7.0.0",
"@rollup/plugin-json": "4.1.0",
"ethers": "5.0.5",
"rollup": "2.21.0",
"rollup-plugin-typescript2": "0.27.1",
"typescript": "3.9.5"
"typescript": "3.9.7"
}
}

@@ -14,3 +14,4 @@ import { constants } from "ethers";

export * from "./SimpleSignedTransferApp";
export * from "./GraphSignedTransferApp";
export * from "./SimpleTwoPartySwapApp";
export * from "./WithdrawApp";

@@ -5,3 +5,3 @@ import {

MiddlewareContext,
NetworkContext,
NetworkContexts,
ProposeMiddlewareContext,

@@ -23,2 +23,3 @@ ProtocolName,

import { AppRegistry } from "./registry";
import { proposeGraphSignedTransferMiddleware } from "./GraphSignedTransferApp";

@@ -52,9 +53,5 @@ const getNameFromAddress = (contractAddress: ContractAddresses, appDefinition: Address) => {

export const generateValidationMiddleware = async (
network: NetworkContext,
supportedTokenAddresses: Address[],
networkContexts: NetworkContexts,
supportedTokenAddresses: { [chainId: number]: Address[] },
): Promise<ValidationMiddleware> => {
if (!network.provider) {
throw new Error(`Validation middleware needs access to a provider`);
}
const validationMiddleware: ValidationMiddleware = async (

@@ -67,3 +64,3 @@ protocol: ProtocolName,

await proposeMiddleware(
network,
networkContexts,
middlewareContext as ProposeMiddlewareContext,

@@ -75,3 +72,3 @@ supportedTokenAddresses,

case ProtocolNames.uninstall: {
await uninstallMiddleware(network, middlewareContext as UninstallMiddlewareContext);
await uninstallMiddleware(networkContexts, middlewareContext as UninstallMiddlewareContext);
break;

@@ -94,10 +91,11 @@ }

const uninstallMiddleware = async (
network: NetworkContext,
networkContexts: NetworkContexts,
middlewareContext: UninstallMiddlewareContext,
) => {
const { appInstance } = middlewareContext;
const { appInstance, stateChannel } = middlewareContext;
const { contractAddresses, provider } = networkContexts[stateChannel.chainId];
const appDef = appInstance.appDefinition;
switch (appDef) {
case network.contractAddresses.DepositApp: {
await uninstallDepositMiddleware(middlewareContext, network.provider);
case contractAddresses.DepositApp: {
await uninstallDepositMiddleware(middlewareContext, provider);
break;

@@ -112,15 +110,20 @@ }

const proposeMiddleware = async (
network: NetworkContext,
networkContexts: NetworkContexts,
middlewareContext: ProposeMiddlewareContext,
supportedTokenAddresses: Address[],
supportedTokenAddresses: { [chainId: number]: Address[] },
) => {
const { contractAddresses } = network;
const { proposal } = middlewareContext;
sharedProposalMiddleware(middlewareContext, contractAddresses, supportedTokenAddresses);
const { proposal, stateChannel } = middlewareContext;
const { contractAddresses, provider } = networkContexts[stateChannel.chainId];
const supportedTokensForChainId = supportedTokenAddresses[stateChannel.chainId];
sharedProposalMiddleware(middlewareContext, contractAddresses, supportedTokensForChainId);
const appDef = proposal.appDefinition;
switch (appDef) {
case contractAddresses.DepositApp: {
await proposeDepositMiddleware(middlewareContext, network.provider);
await proposeDepositMiddleware(middlewareContext, provider);
break;
}
case contractAddresses.GraphSignedTransferApp: {
proposeGraphSignedTransferMiddleware(middlewareContext);
break;
}
case contractAddresses.SimpleTwoPartySwapApp: {

@@ -139,3 +142,3 @@ proposeSwapMiddleware(middlewareContext);

case contractAddresses.HashLockTransferApp: {
await proposeHashLockTransferMiddleware(middlewareContext, network.provider);
await proposeHashLockTransferMiddleware(middlewareContext, provider);
break;

@@ -142,0 +145,0 @@ }

@@ -6,2 +6,3 @@ import { AppRegistryType } from "./shared";

import { SimpleSignedTransferAppRegistryInfo } from "./SimpleSignedTransferApp";
import { GraphSignedTransferAppRegistryInfo } from "./GraphSignedTransferApp";
import { SimpleTwoPartySwapAppRegistryInfo } from "./SimpleTwoPartySwapApp";

@@ -13,2 +14,3 @@ import { WithdrawAppRegistryInfo } from "./WithdrawApp";

SimpleSignedTransferAppRegistryInfo,
GraphSignedTransferAppRegistryInfo,
SimpleTwoPartySwapAppRegistryInfo,

@@ -15,0 +17,0 @@ WithdrawAppRegistryInfo,

@@ -1,7 +0,5 @@

import { AllowedSwap, SwapRate, ProtocolParams } from "@connext/types";
import { calculateExchange, getAddressFromAssetId, stringify } from "@connext/utils";
import { BigNumber, utils } from "ethers";
import { AllowedSwap, ProtocolParams } from "@connext/types";
import { calculateExchangeWad, getAddressFromAssetId, stringify } from "@connext/utils";
import { BigNumber } from "ethers";
const { parseUnits, formatEther } = utils;
const ALLOWED_DISCREPANCY_PCT = 5;

@@ -11,3 +9,3 @@

params: ProtocolParams.Propose,
allowedSwaps: SwapRate[],
allowedSwaps: AllowedSwap[],
ourRate: string,

@@ -23,2 +21,4 @@ responderDecimals: number,

const initiatorDecimals = 18;
const initiatorDepositTokenAddress = getAddressFromAssetId(initiatorDepositAssetId);

@@ -40,6 +40,6 @@ const responderDepositTokenAddress = getAddressFromAssetId(responderDepositAssetId);

const calculatedResponderAmountInWeiUnits = calculateExchange(initiatorDeposit, ourRate);
const calculatedResponderDepositNormalized = parseUnits(
formatEther(calculatedResponderAmountInWeiUnits),
const calculatedResponderDeposit = calculateExchangeWad(
initiatorDeposit,
initiatorDecimals,
ourRate,
responderDecimals,

@@ -49,7 +49,5 @@ );

// make sure calculated within allowed amount
const calculatedToActualDiscrepancy = calculatedResponderDepositNormalized
.sub(responderDeposit)
.abs();
const calculatedToActualDiscrepancy = calculatedResponderDeposit.sub(responderDeposit).abs();
// i.e. (x * (100 - 5)) / 100 = 0.95 * x
const allowedDiscrepancy = calculatedResponderDepositNormalized
const allowedDiscrepancy = calculatedResponderDeposit
.mul(BigNumber.from(100).sub(ALLOWED_DISCREPANCY_PCT))

@@ -60,5 +58,5 @@ .div(100);

throw new Error(
`Responder deposit (${responderDeposit.toString()}) is greater than our expected deposit (${calculatedResponderDepositNormalized.toString()}) based on our swap rate ${ourRate} by more than ${ALLOWED_DISCREPANCY_PCT}% (discrepancy: ${calculatedToActualDiscrepancy.toString()})`,
`Responder deposit (${responderDeposit.toString()}) is greater than our expected deposit (${calculatedResponderDeposit.toString()}) based on our swap rate ${ourRate} by more than ${ALLOWED_DISCREPANCY_PCT}% (discrepancy: ${calculatedToActualDiscrepancy.toString()})`,
);
}
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc