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

@near-eth/aurora-erc20

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@near-eth/aurora-erc20 - npm Package Compare versions

Comparing version 2.5.3 to 2.6.0

26

dist/bridged-erc20/sendToEthereum/index.d.ts
import { ethers } from 'ethers';
import { FinalExecutionOutcome } from 'near-api-js/lib/providers';
import { Account, providers as najProviders } from 'near-api-js';

@@ -33,2 +32,4 @@ import { TransferStatus, TransactionInfo } from '@near-eth/client/dist/types';

proof?: Uint8Array;
auroraEvmAccount?: string;
auroraChainId?: string;
}

@@ -43,2 +44,3 @@ export interface TransferOptions {

ethChainId?: number;
auroraChainId?: string;
nearAccount?: Account;

@@ -49,2 +51,3 @@ nearProvider?: najProviders.Provider;

nep141Factory?: string;
auroraEvmAccount?: string;
}

@@ -68,19 +71,2 @@ export declare const i18n: {

export declare function checkStatus(transfer: Transfer): Promise<Transfer>;
/**
* Parse the burn receipt id and block height needed to complete
* the step BURN
* @param nearBurnTx
* @param nep141Factory
* @param nearProvider
*/
export declare function parseBurnReceipt(nearBurnTx: FinalExecutionOutcome, nep141Factory: string, nearProvider: najProviders.Provider): Promise<{
id: string;
blockHeight: number;
blockTimestamp: number;
event: {
amount: string;
token: string;
recipient: string;
};
}>;
export declare function findAllTransactions({ fromBlock, toBlock, sender, erc20Address, options }: {

@@ -132,5 +118,5 @@ fromBlock: number | string;

* @param params.options.auroraErc20Address params.erc20Address's address on Aurora.
* @param options.auroraEvmAccount Aurora account on NEAR.
* @param params.options.auroraEvmAccount Aurora Cloud silo account on NEAR.
* @param params.options.nep141Factory ERC-20 connector factory to determine the NEAR address.
* @param options.provider Aurora provider to use.
* @param params.options.provider Aurora provider to use.
* @param params.options.nearAccount Connected NEAR wallet account to use.

@@ -137,0 +123,0 @@ * @param params.options.nearProvider NEAR provider.

@@ -29,7 +29,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.checkUnlock = exports.unlock = exports.proofAlreadyUsed = exports.checkSync = exports.checkFinality = exports.checkBurn = exports.burn = exports.initiate = exports.recover = exports.findAllTransfers = exports.findAllTransactions = exports.parseBurnReceipt = exports.checkStatus = exports.act = exports.i18n = exports.TRANSFER_TYPE = exports.DESTINATION_NETWORK = exports.SOURCE_NETWORK = void 0;
exports.checkUnlock = exports.unlock = exports.proofAlreadyUsed = exports.checkSync = exports.checkFinality = exports.checkBurn = exports.burn = exports.initiate = exports.recover = exports.findAllTransfers = exports.findAllTransactions = exports.checkStatus = exports.act = exports.i18n = exports.TRANSFER_TYPE = exports.DESTINATION_NETWORK = exports.SOURCE_NETWORK = void 0;
const utils_1 = require("@near-eth/utils");
const ethers_1 = require("ethers");
const bs58_1 = __importDefault(require("bs58"));
const serialize_1 = require("near-api-js/lib/utils/serialize");
const client_1 = require("@near-eth/client");

@@ -160,45 +159,2 @@ const i18nHelpers_1 = require("@near-eth/client/dist/i18nHelpers");

exports.checkStatus = checkStatus;
/**
* Parse the burn receipt id and block height needed to complete
* the step BURN
* @param nearBurnTx
* @param nep141Factory
* @param nearProvider
*/
async function parseBurnReceipt(nearBurnTx, nep141Factory, nearProvider) {
// @ts-expect-error
const bridgeReceipt = nearBurnTx.receipts_outcome.find(r => r.outcome.executor_id === nep141Factory);
if (!bridgeReceipt) {
throw new Error(`Failed to parse bridge receipt for ${JSON.stringify(nearBurnTx)}`);
}
const successValue = bridgeReceipt.outcome.status.SuccessValue;
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
class BurnEvent {
constructor(args) {
Object.assign(this, args);
}
}
const SCHEMA = new Map([
[BurnEvent, {
kind: 'struct',
fields: [
['flag', 'u8'],
['amount', 'u128'],
['token', [20]],
['recipient', [20]]
]
}]
]);
const rawEvent = (0, serialize_1.deserialize)(SCHEMA, BurnEvent, Buffer.from(successValue, 'base64'));
const event = {
amount: rawEvent.amount.toString(),
token: '0x' + Buffer.from(rawEvent.token).toString('hex'),
recipient: '0x' + Buffer.from(rawEvent.recipient).toString('hex')
};
const receiptBlock = await nearProvider.block({ blockId: bridgeReceipt.block_hash });
const blockHeight = Number(receiptBlock.header.height);
const blockTimestamp = Number(receiptBlock.header.timestamp);
return { id: bridgeReceipt.id, blockHeight, blockTimestamp, event };
}
exports.parseBurnReceipt = parseBurnReceipt;
async function findAllTransactions({ fromBlock, toBlock, sender, erc20Address, options }) {

@@ -208,3 +164,3 @@ var _a, _b, _c;

const bridgeParams = (0, utils_2.getBridgeParams)();
const provider = (_a = options.provider) !== null && _a !== void 0 ? _a : (0, utils_2.getAuroraProvider)();
const provider = (_a = options.provider) !== null && _a !== void 0 ? _a : (0, utils_2.getAuroraCloudProvider)({ auroraEvmAccount: options === null || options === void 0 ? void 0 : options.auroraEvmAccount });
const auroraErc20Address = (_b = options.auroraErc20Address) !== null && _b !== void 0 ? _b : await (0, getAddress_1.default)({ erc20Address, options });

@@ -237,6 +193,6 @@ const auroraErc20 = new ethers_1.ethers.Contract(auroraErc20Address, (_c = options.auroraErc20Abi) !== null && _c !== void 0 ? _c : bridgeParams.auroraErc20Abi, provider);

async function recover(burnTxHash, sender = 'todo', options) {
var _a, _b, _c, _d, _e, _f, _g;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
options = options !== null && options !== void 0 ? options : {};
const nearProvider = (_c = (_a = options.nearProvider) !== null && _a !== void 0 ? _a : (_b = options.nearAccount) === null || _b === void 0 ? void 0 : _b.connection.provider) !== null && _c !== void 0 ? _c : (0, utils_2.getNearProvider)();
const auroraProvider = (_d = options.auroraProvider) !== null && _d !== void 0 ? _d : (0, utils_2.getAuroraProvider)();
const auroraProvider = (_d = options.auroraProvider) !== null && _d !== void 0 ? _d : (0, utils_2.getAuroraCloudProvider)({ auroraEvmAccount: options === null || options === void 0 ? void 0 : options.auroraEvmAccount });
// Ethers formats the receipts and removes nearTransactionHash

@@ -258,7 +214,25 @@ const auroraBurnReceipt = await auroraProvider.send('eth_getTransactionReceipt', [burnTxHash]);

}
const nep141Factory = (_e = options.nep141Factory) !== null && _e !== void 0 ? _e : (0, utils_2.getBridgeParams)().nep141Factory;
const nearBurnReceipt = await parseBurnReceipt(burnTx, nep141Factory, nearProvider);
const { amount, recipient, token: erc20Address } = nearBurnReceipt.event;
const symbol = (_f = options.symbol) !== null && _f !== void 0 ? _f : await (0, getMetadata_1.getSymbol)({ erc20Address, options });
const decimals = (_g = options.decimals) !== null && _g !== void 0 ? _g : await (0, getMetadata_1.getDecimals)({ erc20Address, options });
const bridgeParams = (0, utils_2.getBridgeParams)();
const nep141Factory = (_e = options.nep141Factory) !== null && _e !== void 0 ? _e : bridgeParams.nep141Factory;
let nearBurnReceipt, amount, recipient, symbol, decimals;
if (options.symbol !== 'ETH') {
nearBurnReceipt = await (0, utils_1.parseNep141BurnReceipt)(burnTx, nep141Factory, nearProvider);
amount = nearBurnReceipt.event.amount;
recipient = nearBurnReceipt.event.recipient;
const { token: erc20Address } = nearBurnReceipt.event;
symbol = (_f = options.symbol) !== null && _f !== void 0 ? _f : await (0, getMetadata_1.getSymbol)({ erc20Address, options });
decimals = (_g = options.decimals) !== null && _g !== void 0 ? _g : await (0, getMetadata_1.getDecimals)({ erc20Address, options });
}
else {
// Withdraw ERC-20 ETH from a silo which doesn't use ETH as native currency.
const auroraEvmAccount = (_h = options.auroraEvmAccount) !== null && _h !== void 0 ? _h : bridgeParams.auroraEvmAccount;
nearBurnReceipt = await (0, utils_1.parseETHBurnReceipt)(burnTx, auroraEvmAccount, nearProvider);
amount = nearBurnReceipt.event.amount;
recipient = nearBurnReceipt.event.recipient;
symbol = options.symbol;
decimals = options.decimals;
if (!symbol || !decimals || !auroraEvmAccount) {
throw new Error('Must provide symbol and decimals options to reciver ETH transfer from silo with different native currency');
}
}
const sourceTokenName = 'a' + symbol;

@@ -282,2 +256,4 @@ const destinationTokenName = symbol;

decimals,
auroraEvmAccount: (_j = options.auroraEvmAccount) !== null && _j !== void 0 ? _j : bridgeParams.auroraEvmAccount,
auroraChainId: (_k = options.auroraChainId) !== null && _k !== void 0 ? _k : bridgeParams.auroraChainId,
burnHashes: [burnTxHash],

@@ -305,5 +281,5 @@ nearBurnHashes: [nearBurnTxHash],

* @param params.options.auroraErc20Address params.erc20Address's address on Aurora.
* @param options.auroraEvmAccount Aurora account on NEAR.
* @param params.options.auroraEvmAccount Aurora Cloud silo account on NEAR.
* @param params.options.nep141Factory ERC-20 connector factory to determine the NEAR address.
* @param options.provider Aurora provider to use.
* @param params.options.provider Aurora provider to use.
* @param params.options.nearAccount Connected NEAR wallet account to use.

@@ -315,3 +291,3 @@ * @param params.options.nearProvider NEAR provider.

async function initiate({ erc20Address, amount, recipient, options }) {
var _a, _b, _c, _d, _e, _f;
var _a, _b, _c, _d, _e, _f, _g, _h;
options = options !== null && options !== void 0 ? options : {};

@@ -330,2 +306,3 @@ const provider = (_a = options.provider) !== null && _a !== void 0 ? _a : (0, utils_2.getSignerProvider)();

const sender = (_f = options.sender) !== null && _f !== void 0 ? _f : (await signer.getAddress()).toLowerCase();
const bridgeParams = (0, utils_2.getBridgeParams)();
// various attributes stored as arrays, to keep history of retries

@@ -342,2 +319,4 @@ let transfer = {

sourceTokenName,
auroraEvmAccount: (_g = options.auroraEvmAccount) !== null && _g !== void 0 ? _g : bridgeParams.auroraEvmAccount,
auroraChainId: (_h = options.auroraChainId) !== null && _h !== void 0 ? _h : bridgeParams.auroraChainId,
symbol,

@@ -389,9 +368,9 @@ decimals

async function checkBurn(transfer, options) {
var _a, _b, _c, _d, _e, _f, _g;
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
options = options !== null && options !== void 0 ? options : {};
const bridgeParams = (0, utils_2.getBridgeParams)();
const provider = (_a = options.provider) !== null && _a !== void 0 ? _a : (0, utils_2.getAuroraProvider)();
const provider = (_a = options.provider) !== null && _a !== void 0 ? _a : (0, utils_2.getAuroraCloudProvider)({ auroraEvmAccount: transfer.auroraEvmAccount });
const burnHash = last(transfer.burnHashes);
const ethChainId = (await provider.getNetwork()).chainId;
const expectedChainId = (_b = options.auroraChainId) !== null && _b !== void 0 ? _b : bridgeParams.auroraChainId;
const expectedChainId = (_c = (_b = options.auroraChainId) !== null && _b !== void 0 ? _b : transfer.auroraChainId) !== null && _c !== void 0 ? _c : bridgeParams.auroraChainId;
if (ethChainId !== expectedChainId) {

@@ -454,4 +433,4 @@ throw new Error(`Wrong aurora network for checkLock, expected: ${expectedChainId}, got: ${ethChainId}`);

const nearBurnHash = bs58_1.default.encode(decodedTxHash);
const nearProvider = (_e = (_c = options.nearProvider) !== null && _c !== void 0 ? _c : (_d = options.nearAccount) === null || _d === void 0 ? void 0 : _d.connection.provider) !== null && _e !== void 0 ? _e : (0, utils_2.getNearProvider)();
const nearBurnTx = await nearProvider.txStatus(decodedTxHash, (_f = options.auroraRelayerAccount) !== null && _f !== void 0 ? _f : bridgeParams.auroraRelayerAccount);
const nearProvider = (_f = (_d = options.nearProvider) !== null && _d !== void 0 ? _d : (_e = options.nearAccount) === null || _e === void 0 ? void 0 : _e.connection.provider) !== null && _f !== void 0 ? _f : (0, utils_2.getNearProvider)();
const nearBurnTx = await nearProvider.txStatus(decodedTxHash, (_g = options.auroraRelayerAccount) !== null && _g !== void 0 ? _g : bridgeParams.auroraRelayerAccount);
// @ts-expect-error

@@ -473,5 +452,11 @@ if (nearBurnTx.status.Unknown) {

let nearBurnReceipt;
const nep141Factory = (_g = options.nep141Factory) !== null && _g !== void 0 ? _g : (0, utils_2.getBridgeParams)().nep141Factory;
const nep141Factory = (_h = options.nep141Factory) !== null && _h !== void 0 ? _h : (0, utils_2.getBridgeParams)().nep141Factory;
try {
nearBurnReceipt = await parseBurnReceipt(nearBurnTx, nep141Factory, nearProvider);
if (transfer.symbol !== 'ETH') {
nearBurnReceipt = await (0, utils_1.parseNep141BurnReceipt)(nearBurnTx, nep141Factory, nearProvider);
}
else {
// Withdraw ERC-20 ETH from a silo which doesn't use ETH as native currency.
nearBurnReceipt = await (0, utils_1.parseETHBurnReceipt)(nearBurnTx, (_j = transfer.auroraEvmAccount) !== null && _j !== void 0 ? _j : 'aurora', nearProvider);
}
}

@@ -560,3 +545,8 @@ catch (e) {

if (nearOnEthClientBlockHeight > burnBlockHeight) {
proof = await (0, utils_1.findNearProof)(last(transfer.nearBurnReceiptIds), (_j = options.nep141Factory) !== null && _j !== void 0 ? _j : bridgeParams.nep141Factory, nearOnEthClientBlockHeight, nearProvider, provider, (_k = options.ethClientAddress) !== null && _k !== void 0 ? _k : bridgeParams.ethClientAddress, (_l = options.ethClientAbi) !== null && _l !== void 0 ? _l : bridgeParams.ethClientAbi);
proof = await (0, utils_1.findNearProof)(last(transfer.nearBurnReceiptIds),
// NOTE: If ETH is being transfered with @near-eth/aurora-erc20,
// it means that ETH is not the silo's native currency
transfer.symbol === 'ETH'
? bridgeParams.auroraEvmAccount
: ((_j = options.nep141Factory) !== null && _j !== void 0 ? _j : bridgeParams.nep141Factory), nearOnEthClientBlockHeight, nearProvider, provider, (_k = options.ethClientAddress) !== null && _k !== void 0 ? _k : bridgeParams.ethClientAddress, (_l = options.ethClientAbi) !== null && _l !== void 0 ? _l : bridgeParams.ethClientAbi);
if (await proofAlreadyUsed(provider, proof, (_m = options.erc20LockerAddress) !== null && _m !== void 0 ? _m : bridgeParams.erc20LockerAddress, (_o = options.erc20LockerAbi) !== null && _o !== void 0 ? _o : bridgeParams.erc20LockerAbi)) {

@@ -563,0 +553,0 @@ try {

@@ -33,2 +33,3 @@ import { ethers } from 'ethers';

proof?: Uint8Array;
auroraEvmAccount?: string;
}

@@ -119,3 +120,3 @@ export interface TransferOptions {

* @param params.options.erc20Abi Standard ERC-20 token abi.
* @param options.auroraEvmAccount Aurora account on NEAR.
* @param params.options.auroraEvmAccount Aurora Cloud silo account on NEAR.
* @param params.options.signer Ethers signer to use.

@@ -122,0 +123,0 @@ * @returns The created transfer object.

@@ -167,3 +167,3 @@ "use strict";

async function recover(lockTxHash, options) {
var _a, _b, _c, _d, _e, _f;
var _a, _b, _c, _d, _e, _f, _g;
options = options !== null && options !== void 0 ? options : {};

@@ -209,2 +209,3 @@ const bridgeParams = (0, utils_1.getBridgeParams)();

decimals,
auroraEvmAccount: (_g = options.auroraEvmAccount) !== null && _g !== void 0 ? _g : bridgeParams.auroraEvmAccount,
status: status.IN_PROGRESS,

@@ -237,3 +238,3 @@ lockHashes: [lockTxHash],

* @param params.options.erc20Abi Standard ERC-20 token abi.
* @param options.auroraEvmAccount Aurora account on NEAR.
* @param params.options.auroraEvmAccount Aurora Cloud silo account on NEAR.
* @param params.options.signer Ethers signer to use.

@@ -243,3 +244,3 @@ * @returns The created transfer object.

async function initiate({ erc20Address, amount, recipient, options }) {
var _a, _b, _c, _d, _e;
var _a, _b, _c, _d, _e, _f;
options = options !== null && options !== void 0 ? options : {};

@@ -264,2 +265,3 @@ const provider = (_a = options.provider) !== null && _a !== void 0 ? _a : (0, utils_1.getSignerProvider)();

sourceTokenName,
auroraEvmAccount: (_f = options.auroraEvmAccount) !== null && _f !== void 0 ? _f : (0, utils_1.getBridgeParams)().auroraEvmAccount,
symbol,

@@ -266,0 +268,0 @@ decimals

{
"name": "@near-eth/aurora-erc20",
"version": "2.5.3",
"version": "2.6.0",
"license": "(MIT AND Apache-2.0)",

@@ -18,4 +18,4 @@ "main": "dist/index.js",

"dependencies": {
"@near-eth/client": "1.9.0",
"@near-eth/utils": "2.4.2",
"@near-eth/client": "1.10.0",
"@near-eth/utils": "2.5.0",
"bn.js": "^5.1.3",

@@ -22,0 +22,0 @@ "bs58": "^4.0.1",

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