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

@avalabs/bridge-unified

Package Overview
Dependencies
Maintainers
0
Versions
188
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@avalabs/bridge-unified - npm Package Compare versions

Comparing version 0.0.0-fix-make-source-provider-optio-20240110110812 to 0.0.0-fix-mutate-transfer-object-20241021200141

LICENSE

152

dist/index.d.ts
import { Address } from 'viem';
import { Address as Address$1 } from 'abitype';

@@ -10,32 +11,20 @@ type Chain = {

};
networkToken: Asset;
networkToken: NativeAsset;
};
declare enum AvalancheChainIds {
FUJI = "eip155:43113",
MAINNET = "eip155:43114"
}
declare enum EthereumChainIds {
MAINNET = "eip155:1",
SEPOLIA = "eip155:11155111"
}
type Token = {
address: Address;
name: string;
symbol: string;
decimals: number;
};
type ChainData = {
chainId: string;
domain: number;
tokenRouterAddress: Address;
messageTransmitterAddress: Address;
tokens: Token[];
minimumConfirmations: number;
};
type Config = ChainData[];
declare enum Environment {
DEV = "dev",
PROD = "production",
STAGING = "staging",
TEST = "test"
}
type BridgeServiceConfig = {
environment: Environment;
disabledBridgeTypes?: BridgeType[];
};
type BridgeConfig = Config;
type RequestArguments = {

@@ -78,11 +67,17 @@ method: string;

declare enum ErrorReason {
UNKNOWN = "UNKNOWN",
ASSET_NOT_SUPPORTED = "ASSET_NOT_SUPPORTED",
CHAIN_NOT_SUPPORTED = "CHAIN_NOT_SUPPORTED",
CONFIG_NOT_AVAILABLE = "CONFIG_NOT_AVAILABLE",
INVALID_PARAMS = "INVALID_PARAMS",
CONFIRMATION_COUNT_UNKNOWN = "CONFIRMATION_COUNT_UNKNOWN",
ENVIRONMENT_NOT_SUPPORTED = "ENVIRONMENT_NOT_SUPPORTED",
IDENTICAL_CHAINS_PROVIDED = "IDENTICAL_CHAINS_PROVIDED",
INCORRECT_ADDRESS_PROVIDED = "INCORRECT_ADDRESS_PROVIDED",
INCORRECT_AMOUNT_PROVIDED = "INCORRECT_AMOUNT_PROVIDED",
INCORRECT_ADDRESS_PROVIDED = "INCORRECT_ADDRESS_PROVIDED",
CHAIN_NOT_SUPPORTED = "CHAIN_NOT_SUPPORTED",
ASSET_NOT_SUPPORTED = "ASSET_NOT_SUPPORTED",
CONFIRMATION_COUNT_UNKNOWN = "CONFIRMATION_COUNT_UNKNOWN"
INCORRECT_HASH_PROVIDED = "INCORRECT_HASH_PROVIDED",
INCORRECT_TXHASH_PROVIDED = "INCORRECT_TXHASH_PROVIDED",
INVALID_PARAMS = "INVALID_PARAMS",
UNKNOWN = "UNKNOWN",
VULNERABLE_TOKEN_APPROVAL_ADDRESS = "VULNERABLE_TOKEN_APPROVAL_ADDRESS",
WARDEN_CONFIG_MISMATCH = "WARDEN_CONFIG_MISMATCH",
WARDEN_CONFIG_MISSING_NETWORK = "WARDEN_CONFIG_MISSING_NETWORK"
}

@@ -96,4 +91,3 @@

amount: bigint;
amountDecimals: number;
symbol: string;
asset: BridgeAsset;
completedAt?: number;

@@ -107,3 +101,3 @@ errorCode?: ErrorCode;

sourceConfirmationCount: number;
requiredSourceConfirmationCount: number;
sourceRequiredConfirmationCount: number;
targetChain: Chain;

@@ -114,4 +108,4 @@ targetStartedAt?: number;

targetConfirmationCount: number;
requiredTargetConfirmationCount: number;
startBlockNumber?: bigint;
targetRequiredConfirmationCount: number;
targetStartBlockNumber?: bigint;
metadata?: Record<string, unknown>;

@@ -121,3 +115,5 @@ };

declare enum BridgeType {
CCTP = "cctp"
AVALANCHE_EVM = "avalanche-evm",
CCTP = "cctp",
ICTT_ERC20_ERC20 = "ictt-erc20-erc20"
}

@@ -131,2 +127,12 @@ type FeeParams = {

};
declare enum BridgeSignatureReason {
AllowanceApproval = "allowance-approval",
TokensTransfer = "tokens-transfer",
WrapToken = "wrap-token"
}
type BridgeStepDetails = {
currentSignature: number;
requiredSignatures: number;
currentSignatureReason: BridgeSignatureReason;
};
type TransferParams = {

@@ -141,4 +147,6 @@ asset: BridgeAsset;

targetProvider?: Provider;
sign?: Signer;
onStepChange?: (stepDetails: BridgeStepDetails) => void;
sign: Signer;
};
type GasEstimationParams = Omit<TransferParams, 'sign' | 'onStepChange'>;
type TrackingParams = {

@@ -150,8 +158,29 @@ bridgeTransfer: BridgeTransfer;

};
type AnalyzeTxParams = {
chainId: string;
from: Address$1;
to: Address$1;
tokenTransfers: {
from: Address$1;
to: Address$1;
symbol: string;
}[];
};
type AnalyzeTxResult = {
isBridgeTx: true;
bridgeType: BridgeType;
sourceChainId?: string;
targetChainId?: string;
} | {
isBridgeTx: false;
};
type BridgeService = {
type: BridgeType;
config: BridgeConfig | null;
ensureHasConfig: () => Promise<void>;
updateConfig: () => Promise<void>;
getAssets: () => Promise<ChainAssetMap>;
analyzeTx: (params: AnalyzeTxParams) => AnalyzeTxResult;
estimateGas: (params: GasEstimationParams) => Promise<bigint>;
estimateReceiveAmount: (params: GasEstimationParams) => Promise<{
asset: Asset;
amount: bigint;
}>;
getAssets: () => ChainAssetMap;
getFees: (params: FeeParams) => Promise<AssetFeeMap>;

@@ -163,4 +192,5 @@ transferAsset: (params: TransferParams) => Promise<BridgeTransfer>;

};
getMinimumTransferAmount: (params: FeeParams) => Promise<bigint>;
};
type BridgeServiceFactory = (environment: Environment) => BridgeService;
type BridgeServiceFactory = (environment: Environment) => Promise<BridgeService>;

@@ -171,5 +201,3 @@ declare enum TokenType {

}
type Asset = {
type: TokenType;
address?: Address;
type BaseAsset = {
name: string;

@@ -179,2 +207,12 @@ symbol: string;

};
type Erc20Asset = BaseAsset & {
type: TokenType.ERC20;
address: Address;
};
type NativeAsset = BaseAsset & {
type: TokenType.NATIVE;
};
declare const isErc20Asset: (asset: Asset) => asset is Erc20Asset;
declare const isNativeAsset: (asset: Asset) => asset is NativeAsset;
type Asset = Erc20Asset | NativeAsset;
type DestinationInfo = Record<string, BridgeType[]>;

@@ -187,11 +225,20 @@ type BridgeAsset = Asset & {

declare const createUnifiedBridgeService: ({ environment, disabledBridgeTypes }: BridgeServiceConfig) => {
type BridgeServicesMap = Map<BridgeType, BridgeService>;
type BridgeServiceConfig = {
environment: Environment;
bridges: Map<BridgeType, BridgeService>;
init: () => Promise<void>;
updateConfigs: () => Promise<void>;
enabledBridgeServices: BridgeServicesMap;
};
declare const createUnifiedBridgeService: ({ environment, enabledBridgeServices }: BridgeServiceConfig) => {
canTransferAsset: (asset: BridgeAsset, targetChainId: string) => boolean;
environment: Environment;
estimateGas: (params: GasEstimationParams) => Promise<bigint>;
estimateReceiveAmount: (params: GasEstimationParams) => Promise<{
asset: Asset;
amount: bigint;
}>;
getAssets: () => Promise<ChainAssetMap>;
getFees: (params: FeeParams) => Promise<AssetFeeMap>;
canTransferAsset: (asset: BridgeAsset, targetChainId: string) => boolean;
transferAsset: (params: TransferParams) => Promise<BridgeTransfer>;
analyzeTx: (params: AnalyzeTxParams) => AnalyzeTxResult;
getMinimumTransferAmount: (params: FeeParams) => Promise<bigint>;
trackTransfer: (params: TrackingParams) => {

@@ -201,2 +248,3 @@ cancel: () => void;

};
transferAsset: (params: TransferParams) => Promise<BridgeTransfer>;
};

@@ -213,2 +261,4 @@

export { Asset, AssetFeeMap, BridgeAsset, BridgeConfig, BridgeService, BridgeServiceConfig, BridgeServiceFactory, BridgeTransfer, BridgeType, Chain, ChainAssetMap, DestinationInfo, Dispatch, Environment, ErrorCode, ErrorReason, FeeParams, Hex, Provider, Signer, TokenType, TrackingParams, TransactionRequest, TransferParams, _default as caip2, createUnifiedBridgeService };
declare const getEnabledBridgeServices: (environment: Environment, disabledBridgeTypes: BridgeType[]) => Promise<BridgeServicesMap>;
export { AnalyzeTxParams, AnalyzeTxResult, Asset, AssetFeeMap, AvalancheChainIds, BridgeAsset, BridgeService, BridgeServiceConfig, BridgeServiceFactory, BridgeServicesMap, BridgeSignatureReason, BridgeStepDetails, BridgeTransfer, BridgeType, Chain, ChainAssetMap, DestinationInfo, Dispatch, Environment, Erc20Asset, ErrorCode, ErrorReason, EthereumChainIds, FeeParams, GasEstimationParams, Hex, NativeAsset, Provider, Signer, TokenType, TrackingParams, TransactionRequest, TransferParams, _default as caip2, createUnifiedBridgeService, getEnabledBridgeServices, isErc20Asset, isNativeAsset };
{
"name": "@avalabs/bridge-unified",
"version": "0.0.0-fix-make-source-provider-optio-20240110110812",
"main": "dist/index.js",
"license": "Limited Ecosystem License",
"version": "0.0.0-fix-mutate-transfer-object-20241021200141",
"main": "dist/index.cjs",
"module": "dist/index.js",
"typings": "dist/index.d.ts",
"type": "module",
"files": [
"dist"
],
"dependencies": {
"@noble/hashes": "1.5.0",
"@scure/base": "1.1.9",
"abitype": "0.9.3",
"lodash": "4.17.21",
"viem": "1.19.8"
"viem": "2.11.1",
"zod": "3.23.8"
},

@@ -18,6 +27,7 @@ "devDependencies": {

"@internal/tsup-config": "0.0.1",
"eslint-config-custom": "0.0.0-fix-make-source-provider-optio-20240110110812"
"eslint-config-custom": "0.1.0"
},
"scripts": {
"build": "tsup",
"build:watch": "tsup --watch",
"lint": "eslint \"src/**/*.ts\"",

@@ -24,0 +34,0 @@ "test": "jest",

@@ -40,12 +40,17 @@ <p align="center">

```js
import { createUnifiedBridgeService, Environment, BridgeTransfer } from '@avalabs/bridge-unified';
import { createUnifiedBridgeService, getEnabledBridgeServices, Environment, BridgeTransfer } from '@avalabs/bridge-unified';
// create a new service for an environment
const environment = Environment.TEST;
// use all available bridges
const disabledBridgeTypes = []
// fetch all available bridge services
const enabledBridgeServices = await getEnabledBridgeServices(environment, disabledBridgeTypes);
// create a new service for a given environment and list of bridge services
const unifiedService = createUnifiedBridgeService({
environment: Environment.TEST,
environment,
enabledBridgeServices
});
// init the service, fetch and setup its configs
await unifiedService.init();
// get the list of supported assets, grouped by caip2 (https://chainagnostic.org/CAIPs/caip-2) chain IDs

@@ -77,6 +82,8 @@ const assets = await unifiedService.getAssets()

### createUnifiedBridgeService({ environment, disabledBridgeTypes? })
### getEnabledBridgeServices(environment, disabledBridgeTypes);
Returns a new `unifiedBridgeService` for the given `environment`, using all supported bridge integrations by default. Individual bridges can be turned off via the `disabledBridgeTypes` array.
Type: `(environment: Environment, disabledBridgeTypes: BridgeType[]) => Promise<BridgeServicesMap>`
Returns all available bridge services for a given environment (excluding disabledBridgeTypes). Any bridge service which fails to initialize will be absent from this returned value.
#### environment

@@ -90,6 +97,16 @@

Type: `BridgeType[] | undefined`
Type: `BridgeType[]`
Disables the integration of the provided `BridgeType`s.
#### enabledBridgeServices
Type: `BridgeServicesMap` => `Map<BridgeType, BridgeService>`
This includes all the bridge services which were initialized successfully, to pass to `createUnifiedBridgeService`.
### createUnifiedBridgeService({ environment, enabledBridgeServices })
Returns a new `unifiedBridgeService` for the given `environment` and `enabledBridgeServices` map.
### unifiedBridgeService

@@ -103,7 +120,6 @@

environment, // the provided Environment during initialization
bridges, // the list of enabled bridge integrations
init,
updateConfigs,
getAssets,
getFees,
estimateGas,
canTransferAsset,
transferAsset,

@@ -114,14 +130,2 @@ trackTransfer,

#### init
Type: `() => Promise<void>`
Initializes the unified service by attempting to fetch the configurations of the enabled bridges.
#### updateConfigs
Type: `() => Promise<void>`
Attempts to fetch the configurations of the enabled bridges.
#### getAssets

@@ -139,2 +143,14 @@

#### estimateGas
Type: `(params: TransferParams) => Promise<bigint>`
Estimates the gas cost of a specific transfer.
#### getMinimumTransferAmount
Type: `(params: FeeParams) => Promise<bigint>`
Calculates and returns the minimum transfer amount for a given bridge transfer.
#### transferAsset

@@ -145,3 +161,3 @@

Starts a new bridge transfer, executing every required step in a single call.
Transactions signing is done by either the provided `sourceProvider` or a custom `sign` callback. Clients using their custom `sign` implementation may use their own solution or the default `dispatch` callback to submit the transaction to the network.
Transactions signing is done by a custom `sign` callback. The custom `sign` implementation may use their own solution or the default `dispatch` callback to submit the transaction to the network.
Returns a `BridgeTransfer` containing all the (known) initial values such as: environment, addresses, amount, fee, transaction hash, required and actual block confirmation counts, etc.

@@ -148,0 +164,0 @@

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 too big to display

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