@near-eth/aurora-nep141
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -1,2 +0,2 @@ | ||
export { sendToNear, findAllTransfers } from './sendToNear'; | ||
export { sendToNear, findAllTransfers, recover } from './sendToNear'; | ||
export { default as deploy } from './deploy'; | ||
@@ -3,0 +3,0 @@ export { getAuroraErc20Address, getNep141Address } from './getAddress'; |
@@ -6,6 +6,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getBalance = exports.getNep141Address = exports.getAuroraErc20Address = exports.deploy = exports.findAllTransfers = exports.sendToNear = void 0; | ||
exports.getBalance = exports.getNep141Address = exports.getAuroraErc20Address = exports.deploy = exports.recover = exports.findAllTransfers = exports.sendToNear = void 0; | ||
var sendToNear_1 = require("./sendToNear"); | ||
Object.defineProperty(exports, "sendToNear", { enumerable: true, get: function () { return sendToNear_1.sendToNear; } }); | ||
Object.defineProperty(exports, "findAllTransfers", { enumerable: true, get: function () { return sendToNear_1.findAllTransfers; } }); | ||
Object.defineProperty(exports, "recover", { enumerable: true, get: function () { return sendToNear_1.recover; } }); | ||
var deploy_1 = require("./deploy"); | ||
@@ -12,0 +13,0 @@ Object.defineProperty(exports, "deploy", { enumerable: true, get: function () { return __importDefault(deploy_1).default; } }); |
@@ -50,2 +50,10 @@ import { ethers } from 'ethers'; | ||
}): Promise<Transfer[]>; | ||
export declare function recover(burnTxHash: string, options?: { | ||
provider?: ethers.providers.Provider; | ||
nep141Address?: string; | ||
auroraEvmAccount?: string; | ||
nearAccount?: Account; | ||
decimals?: number; | ||
symbol?: string; | ||
}): Promise<Transfer>; | ||
export declare function checkBurn(transfer: Transfer, options?: { | ||
@@ -52,0 +60,0 @@ provider?: ethers.providers.Provider; |
@@ -22,3 +22,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.burn = exports.sendToNear = exports.checkBurn = exports.findAllTransfers = exports.checkStatus = exports.act = exports.i18n = exports.TRANSFER_TYPE = exports.DESTINATION_NETWORK = exports.SOURCE_NETWORK = void 0; | ||
exports.burn = exports.sendToNear = exports.checkBurn = exports.recover = exports.findAllTransfers = exports.checkStatus = exports.act = exports.i18n = exports.TRANSFER_TYPE = exports.DESTINATION_NETWORK = exports.SOURCE_NETWORK = void 0; | ||
const ethers_1 = require("ethers"); | ||
@@ -30,2 +30,3 @@ const client_1 = require("@near-eth/client"); | ||
const natural_nep141_1 = require("../../natural-nep141"); | ||
const aurora_1 = require("@near-eth/utils/dist/aurora"); | ||
exports.SOURCE_NETWORK = 'aurora'; | ||
@@ -110,5 +111,4 @@ exports.DESTINATION_NETWORK = 'near'; | ||
// Keep only transfers from Aurora to NEAR. | ||
const logId = '0x5a91b8bc9c1981673db8fb226dbd8fcdd0c23f45cd28abb31403a5392f6dd0c7'; | ||
const transferReceipts = receipts.filter((receipt) => receipt.logs.find((log) => log.topics[0] === logId)); | ||
let metadata = { symbol: 'Symbol N/A', decimals: 0 }; | ||
const transferReceipts = receipts.filter((receipt) => receipt.logs.find((log) => log.topics[0] === aurora_1.EXIT_TO_NEAR_SIGNATURE)); | ||
let metadata = { symbol: '', decimals: 0 }; | ||
if (!options.symbol || !options.decimals) { | ||
@@ -123,3 +123,3 @@ metadata = await natural_nep141_1.getMetadata({ nep141Address, options }); | ||
const txBlock = await provider.getBlock(r.blockHash); | ||
const exitLog = r.logs.find(log => log.topics[0] === logId); | ||
const exitLog = r.logs.find(log => log.topics[0] === aurora_1.EXIT_TO_NEAR_SIGNATURE); | ||
const recipientHash = exitLog.topics[3]; | ||
@@ -150,2 +150,44 @@ const amount = ethers_1.ethers.BigNumber.from(exitLog.data).toString(); | ||
exports.findAllTransfers = findAllTransfers; | ||
async function recover(burnTxHash, options) { | ||
var _a, _b, _c, _d; | ||
options = options !== null && options !== void 0 ? options : {}; | ||
const provider = (_a = options.provider) !== null && _a !== void 0 ? _a : client_1.getAuroraProvider(); | ||
const receipt = await provider.getTransactionReceipt(burnTxHash); | ||
const exitLog = receipt.logs.find(log => log.topics[0] === aurora_1.EXIT_TO_NEAR_SIGNATURE); | ||
const burnLog = receipt.logs.find(log => log.topics[0] === aurora_1.BURN_SIGNATURE); | ||
const recipientHash = exitLog.topics[3]; | ||
const amount = ethers_1.ethers.BigNumber.from(exitLog.data).toString(); | ||
const auroraErc20Address = '0x' + exitLog.topics[1].slice(26); | ||
const sender = '0x' + burnLog.topics[1].slice(26); | ||
let metadata = { symbol: '', decimals: 0 }; | ||
if (!options.symbol || !options.decimals) { | ||
const nep141Address = (_b = options.nep141Address) !== null && _b !== void 0 ? _b : await getAddress_1.getNep141Address({ auroraErc20Address, options }); | ||
metadata = await natural_nep141_1.getMetadata({ nep141Address: nep141Address, options }); | ||
} | ||
const symbol = (_c = options.symbol) !== null && _c !== void 0 ? _c : metadata.symbol; | ||
const sourceTokenName = symbol; | ||
const destinationTokenName = symbol; | ||
const decimals = (_d = options.decimals) !== null && _d !== void 0 ? _d : metadata.decimals; | ||
const txBlock = await provider.getBlock(receipt.blockHash); | ||
const transfer = { | ||
id: Math.random().toString().slice(2), | ||
startTime: new Date(txBlock.timestamp * 1000).toISOString(), | ||
type: exports.TRANSFER_TYPE, | ||
status: status.COMPLETE, | ||
completedStep: BURN, | ||
errors: [], | ||
amount, | ||
decimals, | ||
symbol, | ||
sourceToken: auroraErc20Address, | ||
sourceTokenName, | ||
destinationTokenName, | ||
sender, | ||
recipient: `NEAR account hash: ${recipientHash}`, | ||
burnHashes: [receipt.transactionHash], | ||
burnReceipts: [] | ||
}; | ||
return transfer; | ||
} | ||
exports.recover = recover; | ||
async function checkBurn(transfer, options) { | ||
@@ -222,3 +264,3 @@ var _a, _b; | ||
const provider = (_a = options.provider) !== null && _a !== void 0 ? _a : client_1.getSignerProvider(); | ||
let metadata = { symbol: 'Symbol N/A', decimals: 0 }; | ||
let metadata = { symbol: '', decimals: 0 }; | ||
if (!options.symbol || !options.decimals) { | ||
@@ -225,0 +267,0 @@ metadata = await natural_nep141_1.getMetadata({ nep141Address, options }); |
@@ -1,2 +0,2 @@ | ||
export { sendToNear, findAllTransfers } from './sendToNear'; | ||
export { sendToNear, findAllTransfers, recover } from './sendToNear'; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.findAllTransfers = exports.sendToNear = void 0; | ||
exports.recover = exports.findAllTransfers = exports.sendToNear = void 0; | ||
var sendToNear_1 = require("./sendToNear"); | ||
Object.defineProperty(exports, "sendToNear", { enumerable: true, get: function () { return sendToNear_1.sendToNear; } }); | ||
Object.defineProperty(exports, "findAllTransfers", { enumerable: true, get: function () { return sendToNear_1.findAllTransfers; } }); | ||
Object.defineProperty(exports, "recover", { enumerable: true, get: function () { return sendToNear_1.recover; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -43,2 +43,6 @@ import { ethers } from 'ethers'; | ||
}): Promise<Transfer[]>; | ||
export declare function recover(burnTxHash: string, options?: { | ||
provider?: ethers.providers.Provider; | ||
etherExitToNearPrecompile?: string; | ||
}): Promise<Transfer>; | ||
export declare function checkBurn(transfer: Transfer, options?: { | ||
@@ -45,0 +49,0 @@ provider?: ethers.providers.Provider; |
@@ -22,3 +22,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.burn = exports.sendToNear = exports.checkBurn = exports.findAllTransfers = exports.checkStatus = exports.act = exports.i18n = exports.TRANSFER_TYPE = exports.DESTINATION_NETWORK = exports.SOURCE_NETWORK = void 0; | ||
exports.burn = exports.sendToNear = exports.checkBurn = exports.recover = exports.findAllTransfers = exports.checkStatus = exports.act = exports.i18n = exports.TRANSFER_TYPE = exports.DESTINATION_NETWORK = exports.SOURCE_NETWORK = void 0; | ||
const ethers_1 = require("ethers"); | ||
@@ -28,2 +28,3 @@ const client_1 = require("@near-eth/client"); | ||
const find_replacement_tx_1 = require("find-replacement-tx"); | ||
const aurora_1 = require("@near-eth/utils/dist/aurora"); | ||
exports.SOURCE_NETWORK = 'aurora'; | ||
@@ -99,3 +100,2 @@ exports.DESTINATION_NETWORK = 'near'; | ||
const provider = (_a = options.provider) !== null && _a !== void 0 ? _a : client_1.getAuroraProvider(); | ||
const logId = '0x5a91b8bc9c1981673db8fb226dbd8fcdd0c23f45cd28abb31403a5392f6dd0c7'; | ||
const filter = { | ||
@@ -105,3 +105,3 @@ address: (_b = options.etherExitToNearPrecompile) !== null && _b !== void 0 ? _b : bridgeParams.etherExitToNearPrecompile, | ||
toBlock, | ||
topics: [logId, ethers_1.ethers.utils.hexZeroPad(sender, 32)] | ||
topics: [aurora_1.EXIT_TO_NEAR_SIGNATURE, ethers_1.ethers.utils.hexZeroPad(sender, 32)] | ||
}; | ||
@@ -135,2 +135,38 @@ const logs = await provider.getLogs(filter); | ||
exports.findAllTransfers = findAllTransfers; | ||
async function recover(burnTxHash, options) { | ||
var _a, _b; | ||
options = options !== null && options !== void 0 ? options : {}; | ||
const provider = (_a = options.provider) !== null && _a !== void 0 ? _a : client_1.getAuroraProvider(); | ||
const bridgeParams = client_1.getBridgeParams(); | ||
const receipt = await provider.getTransactionReceipt(burnTxHash); | ||
const exitLog = receipt.logs.find(log => log.topics[0] === aurora_1.EXIT_TO_NEAR_SIGNATURE); | ||
const etherExitToNearPrecompile = (_b = options.etherExitToNearPrecompile) !== null && _b !== void 0 ? _b : bridgeParams.etherExitToNearPrecompile; | ||
if (exitLog.address.toLowerCase() !== etherExitToNearPrecompile.toLowerCase()) { | ||
throw new Error(`Failed to verify exit log precompile address ${JSON.stringify(exitLog)}`); | ||
} | ||
const recipientHash = exitLog.topics[3]; | ||
const amount = ethers_1.ethers.BigNumber.from(exitLog.data).toString(); | ||
const sender = '0x' + exitLog.topics[1].slice(26); | ||
const txBlock = await provider.getBlock(receipt.blockHash); | ||
const transfer = { | ||
id: Math.random().toString().slice(2), | ||
startTime: new Date(txBlock.timestamp * 1000).toISOString(), | ||
type: exports.TRANSFER_TYPE, | ||
status: status.COMPLETE, | ||
completedStep: BURN, | ||
errors: [], | ||
amount, | ||
decimals: 18, | ||
symbol: 'ETH', | ||
sourceToken: 'ETH', | ||
sourceTokenName: 'ETH', | ||
destinationTokenName: 'ETH', | ||
sender, | ||
recipient: `NEAR account hash: ${recipientHash}`, | ||
burnHashes: [receipt.transactionHash], | ||
burnReceipts: [] | ||
}; | ||
return transfer; | ||
} | ||
exports.recover = recover; | ||
async function checkBurn(transfer, options) { | ||
@@ -137,0 +173,0 @@ var _a, _b; |
@@ -1,5 +0,4 @@ | ||
export { sendToAurora, wrapAndSendNearToAurora } from './sendToAurora'; | ||
export { sendToAurora, wrapAndSendNearToAurora, findAllTransfers, recover } from './sendToAurora'; | ||
export { default as getMetadata } from './getMetadata'; | ||
export { default as getBalance } from './getBalance'; | ||
export { findAllTransfers } from './sendToAurora'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -6,6 +6,8 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.findAllTransfers = exports.getBalance = exports.getMetadata = exports.wrapAndSendNearToAurora = exports.sendToAurora = void 0; | ||
exports.getBalance = exports.getMetadata = exports.recover = exports.findAllTransfers = exports.wrapAndSendNearToAurora = exports.sendToAurora = void 0; | ||
var sendToAurora_1 = require("./sendToAurora"); | ||
Object.defineProperty(exports, "sendToAurora", { enumerable: true, get: function () { return sendToAurora_1.sendToAurora; } }); | ||
Object.defineProperty(exports, "wrapAndSendNearToAurora", { enumerable: true, get: function () { return sendToAurora_1.wrapAndSendNearToAurora; } }); | ||
Object.defineProperty(exports, "findAllTransfers", { enumerable: true, get: function () { return sendToAurora_1.findAllTransfers; } }); | ||
Object.defineProperty(exports, "recover", { enumerable: true, get: function () { return sendToAurora_1.recover; } }); | ||
var getMetadata_1 = require("./getMetadata"); | ||
@@ -15,4 +17,2 @@ Object.defineProperty(exports, "getMetadata", { enumerable: true, get: function () { return __importDefault(getMetadata_1).default; } }); | ||
Object.defineProperty(exports, "getBalance", { enumerable: true, get: function () { return __importDefault(getBalance_1).default; } }); | ||
var sendToAurora_2 = require("./sendToAurora"); | ||
Object.defineProperty(exports, "findAllTransfers", { enumerable: true, get: function () { return sendToAurora_2.findAllTransfers; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -54,3 +54,3 @@ import { ethers } from 'ethers'; | ||
nep141Address: string; | ||
callIndexer: (query: string) => [ | ||
callIndexer: (query: string) => Promise<[ | ||
{ | ||
@@ -67,3 +67,3 @@ originated_from_transaction_hash: string; | ||
} | ||
]; | ||
]>; | ||
options?: { | ||
@@ -76,2 +76,21 @@ auroraEvmAccount?: string; | ||
}): Promise<Transfer[]>; | ||
export declare function recover(lockTxHash: string, callIndexer: (query: string) => Promise<[ | ||
{ | ||
included_in_block_timestamp: string; | ||
receipt_predecessor_account_id: string; | ||
args: { | ||
method_name: string; | ||
args_json: { | ||
msg: string; | ||
amount: string; | ||
sender_id: string; | ||
}; | ||
}; | ||
} | ||
]>, options?: { | ||
nearAccount?: Account; | ||
decimals?: number; | ||
symbol?: string; | ||
auroraEvmAccount?: string; | ||
}): Promise<Transfer>; | ||
export declare function checkLock(transfer: Transfer, options?: { | ||
@@ -78,0 +97,0 @@ nearAccount?: Account; |
@@ -25,3 +25,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getStorageBalance = exports.getMinStorageBalance = exports.lockNear = exports.wrapAndSendNearToAurora = exports.lock = exports.sendToAurora = exports.checkLock = exports.findAllTransfers = exports.checkStatus = exports.act = exports.i18n = exports.TRANSFER_TYPE = exports.DESTINATION_NETWORK = exports.SOURCE_NETWORK = void 0; | ||
exports.getStorageBalance = exports.getMinStorageBalance = exports.lockNear = exports.wrapAndSendNearToAurora = exports.lock = exports.sendToAurora = exports.checkLock = exports.recover = exports.findAllTransfers = exports.checkStatus = exports.act = exports.i18n = exports.TRANSFER_TYPE = exports.DESTINATION_NETWORK = exports.SOURCE_NETWORK = void 0; | ||
const bn_js_1 = __importDefault(require("bn.js")); | ||
@@ -133,3 +133,3 @@ const near_api_js_1 = require("near-api-js"); | ||
// TODO also use getMetadata for aurora (nETH) when available | ||
let metadata = { symbol: 'Symbol N/A', decimals: 0 }; | ||
let metadata = { symbol: '', decimals: 0 }; | ||
if (nep141Address === auroraEvmAccount) { | ||
@@ -187,2 +187,56 @@ metadata = { decimals: 18, symbol: 'ETH' }; | ||
exports.findAllTransfers = findAllTransfers; | ||
async function recover(lockTxHash, callIndexer, options) { | ||
var _a, _b, _c; | ||
options = options !== null && options !== void 0 ? options : {}; | ||
const bridgeParams = client_1.getBridgeParams(); | ||
const auroraEvmAccount = (_a = options.auroraEvmAccount) !== null && _a !== void 0 ? _a : bridgeParams.auroraEvmAccount; | ||
const actionReceipts = await callIndexer(`SELECT public.receipts.included_in_block_timestamp, | ||
public.action_receipt_actions.receipt_predecessor_account_id, public.action_receipt_actions.args | ||
FROM public.receipts | ||
JOIN public.action_receipt_actions | ||
ON public.action_receipt_actions.receipt_id = public.receipts.receipt_id | ||
WHERE (originated_from_transaction_hash = '${lockTxHash}' | ||
AND receiver_account_id = '${auroraEvmAccount}' | ||
)`); | ||
const [lockToAuroraActionReceipt] = actionReceipts.filter( | ||
// When sending nETH, msg = near_sender:eth_addr | ||
// When sending other nep141, msg = eth_addr | ||
r => r.args.method_name === 'ft_on_transfer' && /^[a-f0-9]{40}$/.test(r.args.args_json.msg.slice(r.args.args_json.msg.length - 40))); | ||
if (!lockToAuroraActionReceipt) { | ||
throw new Error(`Failed to verify ${auroraEvmAccount} ft_on_transfer action receipt: ${JSON.stringify(actionReceipts)}`); | ||
} | ||
const nep141Address = lockToAuroraActionReceipt.receipt_predecessor_account_id; | ||
let metadata = { symbol: '', decimals: 0 }; | ||
if (nep141Address === auroraEvmAccount) { | ||
metadata = { decimals: 18, symbol: 'ETH' }; | ||
} | ||
else if (!options.symbol || !options.decimals) { | ||
metadata = await getMetadata_1.default({ nep141Address, options }); | ||
} | ||
const symbol = (_b = options.symbol) !== null && _b !== void 0 ? _b : metadata.symbol; | ||
const decimals = (_c = options.decimals) !== null && _c !== void 0 ? _c : metadata.decimals; | ||
let sender = lockToAuroraActionReceipt.args.args_json.sender_id; | ||
if (sender === auroraEvmAccount) { | ||
const msg = lockToAuroraActionReceipt.args.args_json.msg; | ||
sender = msg.substr(0, msg.indexOf(':')); | ||
} | ||
return { | ||
type: exports.TRANSFER_TYPE, | ||
id: Math.random().toString().slice(2), | ||
startTime: new Date(Number(lockToAuroraActionReceipt.included_in_block_timestamp) / 10 ** 6).toISOString(), | ||
amount: lockToAuroraActionReceipt.args.args_json.amount, | ||
decimals, | ||
symbol, | ||
sourceToken: nep141Address, | ||
sourceTokenName: metadata.symbol, | ||
destinationTokenName: 'a' + metadata.symbol, | ||
sender, | ||
recipient: '0x' + lockToAuroraActionReceipt.args.args_json.msg.slice(lockToAuroraActionReceipt.args.args_json.msg.length - 40), | ||
status: status.COMPLETE, | ||
completedStep: LOCK, | ||
errors: [], | ||
lockHashes: [lockTxHash] | ||
}; | ||
} | ||
exports.recover = recover; | ||
async function checkLock(transfer, options) { | ||
@@ -243,3 +297,3 @@ var _a; | ||
options = options !== null && options !== void 0 ? options : {}; | ||
let metadata = { symbol: 'Symbol N/A', decimals: 0 }; | ||
let metadata = { symbol: '', decimals: 0 }; | ||
if (!options.symbol || !options.decimals) { | ||
@@ -246,0 +300,0 @@ metadata = await getMetadata_1.default({ nep141Address, options }); |
{ | ||
"name": "@near-eth/aurora-nep141", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"license": "(MIT AND Apache-2.0)", | ||
@@ -24,3 +24,3 @@ "main": "dist/index.js", | ||
"@near-eth/client": "1.8.0", | ||
"@near-eth/utils": "2.1.1", | ||
"@near-eth/utils": "2.1.2", | ||
"bn.js": "^5.1.3", | ||
@@ -27,0 +27,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
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
132545
1708
+ Added@near-eth/utils@2.1.2(transitive)
+ Added@types/node@22.13.4(transitive)
- Removed@near-eth/utils@2.1.1(transitive)
- Removed@types/node@22.13.5(transitive)
Updated@near-eth/utils@2.1.2