@atomiqlabs/chain-evm 2.1.11 → 2.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -0
- package/dist/chains/EVMOptions.d.ts +66 -0
- package/dist/chains/EVMOptions.js +2 -0
- package/dist/chains/alpen/AlpenInitializer.d.ts +3 -30
- package/dist/chains/alpen/AlpenInitializer.js +3 -3
- package/dist/chains/botanix/BotanixInitializer.d.ts +3 -30
- package/dist/chains/botanix/BotanixInitializer.js +3 -3
- package/dist/chains/citrea/CitreaBtcRelay.d.ts +5 -0
- package/dist/chains/citrea/CitreaBtcRelay.js +7 -2
- package/dist/chains/citrea/CitreaFees.d.ts +3 -5
- package/dist/chains/citrea/CitreaFees.js +3 -5
- package/dist/chains/citrea/CitreaInitializer.d.ts +3 -29
- package/dist/chains/citrea/CitreaInitializer.js +3 -3
- package/dist/chains/citrea/CitreaSpvVaultContract.d.ts +5 -0
- package/dist/chains/citrea/CitreaSpvVaultContract.js +7 -2
- package/dist/chains/citrea/CitreaSwapContract.d.ts +7 -2
- package/dist/chains/citrea/CitreaSwapContract.js +10 -5
- package/dist/chains/citrea/CitreaTokens.d.ts +5 -0
- package/dist/chains/citrea/CitreaTokens.js +5 -0
- package/dist/chains/goat/GoatInitializer.d.ts +3 -30
- package/dist/chains/goat/GoatInitializer.js +3 -3
- package/dist/evm/btcrelay/EVMBtcRelay.d.ts +41 -10
- package/dist/evm/btcrelay/EVMBtcRelay.js +50 -18
- package/dist/evm/btcrelay/headers/EVMBtcHeader.d.ts +53 -7
- package/dist/evm/btcrelay/headers/EVMBtcHeader.js +43 -5
- package/dist/evm/btcrelay/headers/EVMBtcStoredHeader.d.ts +53 -8
- package/dist/evm/btcrelay/headers/EVMBtcStoredHeader.js +41 -1
- package/dist/evm/chain/EVMChainInterface.d.ts +57 -2
- package/dist/evm/chain/EVMChainInterface.js +7 -7
- package/dist/evm/chain/EVMModule.d.ts +5 -0
- package/dist/evm/chain/EVMModule.js +6 -1
- package/dist/evm/chain/modules/EVMBlocks.d.ts +7 -0
- package/dist/evm/chain/modules/EVMBlocks.js +2 -0
- package/dist/evm/chain/modules/EVMEvents.js +19 -19
- package/dist/evm/chain/modules/EVMFees.d.ts +41 -5
- package/dist/evm/chain/modules/EVMFees.js +24 -5
- package/dist/evm/chain/modules/EVMTokens.d.ts +1 -1
- package/dist/evm/chain/modules/EVMTokens.js +1 -1
- package/dist/evm/chain/modules/EVMTransactions.d.ts +20 -2
- package/dist/evm/chain/modules/EVMTransactions.js +11 -8
- package/dist/evm/contract/EVMContractBase.d.ts +28 -10
- package/dist/evm/contract/EVMContractBase.js +9 -18
- package/dist/evm/contract/EVMContractModule.d.ts +5 -0
- package/dist/evm/contract/EVMContractModule.js +5 -0
- package/dist/evm/contract/modules/EVMContractEvents.d.ts +7 -1
- package/dist/evm/contract/modules/EVMContractEvents.js +23 -3
- package/dist/evm/events/EVMChainEvents.d.ts +8 -0
- package/dist/evm/events/EVMChainEvents.js +8 -0
- package/dist/evm/events/EVMChainEventsBrowser.d.ts +87 -19
- package/dist/evm/events/EVMChainEventsBrowser.js +53 -18
- package/dist/evm/providers/JsonRpcProviderWithRetries.d.ts +9 -0
- package/dist/evm/providers/JsonRpcProviderWithRetries.js +9 -0
- package/dist/evm/providers/ReconnectingWebSocketProvider.d.ts +5 -0
- package/dist/evm/providers/ReconnectingWebSocketProvider.js +5 -0
- package/dist/evm/providers/WebSocketProviderWithRetries.d.ts +9 -0
- package/dist/evm/providers/WebSocketProviderWithRetries.js +9 -0
- package/dist/evm/spv_swap/EVMSpvVaultContract.d.ts +46 -21
- package/dist/evm/spv_swap/EVMSpvVaultContract.js +62 -22
- package/dist/evm/spv_swap/EVMSpvVaultData.d.ts +57 -2
- package/dist/evm/spv_swap/EVMSpvVaultData.js +57 -2
- package/dist/evm/spv_swap/EVMSpvWithdrawalData.d.ts +12 -0
- package/dist/evm/spv_swap/EVMSpvWithdrawalData.js +12 -0
- package/dist/evm/swaps/EVMSwapContract.d.ts +58 -13
- package/dist/evm/swaps/EVMSwapContract.js +81 -54
- package/dist/evm/swaps/EVMSwapData.d.ts +27 -6
- package/dist/evm/swaps/EVMSwapData.js +26 -0
- package/dist/evm/swaps/EVMSwapModule.d.ts +5 -0
- package/dist/evm/swaps/EVMSwapModule.js +5 -0
- package/dist/evm/swaps/handlers/IHandler.d.ts +5 -0
- package/dist/evm/swaps/handlers/claim/ClaimHandlers.d.ts +15 -0
- package/dist/evm/swaps/handlers/claim/ClaimHandlers.js +5 -0
- package/dist/evm/swaps/handlers/claim/btc/BitcoinNoncedOutputClaimHandler.d.ts +5 -0
- package/dist/evm/swaps/handlers/claim/btc/BitcoinOutputClaimHandler.d.ts +10 -0
- package/dist/evm/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.d.ts +5 -0
- package/dist/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.d.ts +15 -0
- package/dist/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.js +7 -2
- package/dist/evm/swaps/modules/EVMLpVault.d.ts +5 -0
- package/dist/evm/swaps/modules/EVMLpVault.js +9 -4
- package/dist/evm/swaps/modules/EVMSwapClaim.d.ts +7 -2
- package/dist/evm/swaps/modules/EVMSwapClaim.js +11 -6
- package/dist/evm/swaps/modules/EVMSwapInit.d.ts +10 -0
- package/dist/evm/swaps/modules/EVMSwapInit.js +11 -6
- package/dist/evm/swaps/modules/EVMSwapRefund.d.ts +5 -0
- package/dist/evm/swaps/modules/EVMSwapRefund.js +9 -4
- package/dist/evm/wallet/EVMBrowserSigner.d.ts +22 -2
- package/dist/evm/wallet/EVMBrowserSigner.js +40 -2
- package/dist/evm/wallet/EVMPersistentSigner.d.ts +13 -2
- package/dist/evm/wallet/EVMPersistentSigner.js +13 -1
- package/dist/evm/wallet/EVMSigner.d.ts +30 -1
- package/dist/evm/wallet/EVMSigner.js +34 -1
- package/dist/index.d.ts +71 -0
- package/dist/index.js +70 -0
- package/dist/node/index.d.ts +10 -0
- package/dist/node/index.js +15 -0
- package/dist/utils/Utils.d.ts +50 -0
- package/dist/utils/Utils.js +45 -0
- package/node/index.d.ts +1 -0
- package/node/index.js +3 -0
- package/package.json +4 -3
- package/src/chains/EVMOptions.ts +70 -0
- package/src/chains/alpen/AlpenInitializer.ts +5 -27
- package/src/chains/botanix/BotanixChainType.ts +5 -5
- package/src/chains/botanix/BotanixInitializer.ts +5 -27
- package/src/chains/citrea/CitreaBtcRelay.ts +8 -3
- package/src/chains/citrea/CitreaFees.ts +3 -6
- package/src/chains/citrea/CitreaInitializer.ts +5 -27
- package/src/chains/citrea/CitreaSpvVaultContract.ts +7 -2
- package/src/chains/citrea/CitreaSwapContract.ts +11 -6
- package/src/chains/citrea/CitreaTokens.ts +6 -1
- package/src/chains/goat/GoatChainType.ts +5 -5
- package/src/chains/goat/GoatInitializer.ts +3 -25
- package/src/evm/btcrelay/EVMBtcRelay.ts +54 -22
- package/src/evm/btcrelay/headers/EVMBtcHeader.ts +60 -13
- package/src/evm/btcrelay/headers/EVMBtcStoredHeader.ts +55 -10
- package/src/evm/chain/EVMChainInterface.ts +66 -14
- package/src/evm/chain/EVMModule.ts +6 -1
- package/src/evm/chain/modules/EVMBlocks.ts +7 -0
- package/src/evm/chain/modules/EVMEvents.ts +19 -19
- package/src/evm/chain/modules/EVMFees.ts +41 -5
- package/src/evm/chain/modules/EVMTokens.ts +1 -1
- package/src/evm/chain/modules/EVMTransactions.ts +27 -8
- package/src/evm/contract/EVMContractBase.ts +29 -24
- package/src/evm/contract/EVMContractModule.ts +5 -0
- package/src/evm/contract/modules/EVMContractEvents.ts +27 -8
- package/src/evm/events/EVMChainEvents.ts +8 -0
- package/src/evm/events/EVMChainEventsBrowser.ts +103 -29
- package/src/evm/providers/JsonRpcProviderWithRetries.ts +10 -1
- package/src/evm/providers/ReconnectingWebSocketProvider.ts +6 -1
- package/src/evm/providers/WebSocketProviderWithRetries.ts +10 -1
- package/src/evm/spv_swap/EVMSpvVaultContract.ts +73 -31
- package/src/evm/spv_swap/EVMSpvVaultData.ts +57 -2
- package/src/evm/spv_swap/EVMSpvWithdrawalData.ts +12 -0
- package/src/evm/swaps/EVMSwapContract.ts +108 -63
- package/src/evm/swaps/EVMSwapData.ts +27 -1
- package/src/evm/swaps/EVMSwapModule.ts +5 -0
- package/src/evm/swaps/handlers/IHandler.ts +5 -0
- package/src/evm/swaps/handlers/claim/ClaimHandlers.ts +15 -0
- package/src/evm/swaps/handlers/claim/btc/BitcoinNoncedOutputClaimHandler.ts +5 -0
- package/src/evm/swaps/handlers/claim/btc/BitcoinOutputClaimHandler.ts +10 -0
- package/src/evm/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.ts +5 -0
- package/src/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.ts +17 -2
- package/src/evm/swaps/modules/EVMLpVault.ts +10 -5
- package/src/evm/swaps/modules/EVMSwapClaim.ts +12 -7
- package/src/evm/swaps/modules/EVMSwapInit.ts +17 -7
- package/src/evm/swaps/modules/EVMSwapRefund.ts +9 -4
- package/src/evm/wallet/EVMBrowserSigner.ts +44 -5
- package/src/evm/wallet/EVMPersistentSigner.ts +14 -2
- package/src/evm/wallet/EVMSigner.ts +37 -1
- package/src/index.ts +72 -0
- package/src/node/index.ts +10 -0
- package/src/utils/Utils.ts +50 -1
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import { ChainSwapType } from "@atomiqlabs/base";
|
|
2
2
|
import { IHandler } from "../IHandler";
|
|
3
|
+
/**
|
|
4
|
+
* Base interface for claim handlers with explicit chain swap type.
|
|
5
|
+
*
|
|
6
|
+
* @category Internal/Handlers
|
|
7
|
+
*/
|
|
3
8
|
export interface IClaimHandler<C, W> extends IHandler<C, W> {
|
|
4
9
|
getType(): ChainSwapType;
|
|
5
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Claim handler constructor contract with static metadata used during handler registration.
|
|
13
|
+
*
|
|
14
|
+
* @category Internal/Handlers
|
|
15
|
+
*/
|
|
6
16
|
export type ClaimHandlerType = {
|
|
7
17
|
gas: number;
|
|
8
18
|
type: ChainSwapType;
|
|
9
19
|
} & (new (address: string) => IClaimHandler<any, any>);
|
|
20
|
+
/**
|
|
21
|
+
* Supported claim handler implementations for EVM swap contract initialization.
|
|
22
|
+
*
|
|
23
|
+
* @category Internal/Handlers
|
|
24
|
+
*/
|
|
10
25
|
export declare const claimHandlersList: ClaimHandlerType[];
|
|
@@ -5,6 +5,11 @@ const HashlockClaimHandler_1 = require("./HashlockClaimHandler");
|
|
|
5
5
|
const BitcoinTxIdClaimHandler_1 = require("./btc/BitcoinTxIdClaimHandler");
|
|
6
6
|
const BitcoinOutputClaimHandler_1 = require("./btc/BitcoinOutputClaimHandler");
|
|
7
7
|
const BitcoinNoncedOutputClaimHandler_1 = require("./btc/BitcoinNoncedOutputClaimHandler");
|
|
8
|
+
/**
|
|
9
|
+
* Supported claim handler implementations for EVM swap contract initialization.
|
|
10
|
+
*
|
|
11
|
+
* @category Internal/Handlers
|
|
12
|
+
*/
|
|
8
13
|
exports.claimHandlersList = [
|
|
9
14
|
HashlockClaimHandler_1.HashlockClaimHandler,
|
|
10
15
|
BitcoinTxIdClaimHandler_1.BitcoinTxIdClaimHandler,
|
|
@@ -6,6 +6,11 @@ import { BitcoinOutputWitnessData } from "./BitcoinOutputClaimHandler";
|
|
|
6
6
|
import { Buffer } from "buffer";
|
|
7
7
|
import { EVMSwapData } from "../../../EVMSwapData";
|
|
8
8
|
import { EVMTx } from "../../../../chain/modules/EVMTransactions";
|
|
9
|
+
/**
|
|
10
|
+
* Commitment payload for nonced output-script bitcoin claims.
|
|
11
|
+
*
|
|
12
|
+
* @category Internal/Handlers
|
|
13
|
+
*/
|
|
9
14
|
export type BitcoinNoncedOutputCommitmentData = {
|
|
10
15
|
output: Buffer;
|
|
11
16
|
amount: bigint;
|
|
@@ -5,10 +5,20 @@ import { BitcoinCommitmentData, BitcoinWitnessData, IBitcoinClaimHandler } from
|
|
|
5
5
|
import { Buffer } from "buffer";
|
|
6
6
|
import { EVMTx } from "../../../../chain/modules/EVMTransactions";
|
|
7
7
|
import { EVMSwapData } from "../../../EVMSwapData";
|
|
8
|
+
/**
|
|
9
|
+
* Commitment payload for output-script bitcoin claims.
|
|
10
|
+
*
|
|
11
|
+
* @category Internal/Handlers
|
|
12
|
+
*/
|
|
8
13
|
export type BitcoinOutputCommitmentData = {
|
|
9
14
|
output: Buffer;
|
|
10
15
|
amount: bigint;
|
|
11
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Witness input for output-script bitcoin claims.
|
|
19
|
+
*
|
|
20
|
+
* @category Internal/Handlers
|
|
21
|
+
*/
|
|
12
22
|
export type BitcoinOutputWitnessData = BitcoinWitnessData & {
|
|
13
23
|
vout: number;
|
|
14
24
|
};
|
|
@@ -5,6 +5,11 @@ import { BitcoinCommitmentData, BitcoinWitnessData, IBitcoinClaimHandler } from
|
|
|
5
5
|
import { Buffer } from "buffer";
|
|
6
6
|
import { EVMSwapData } from "../../../EVMSwapData";
|
|
7
7
|
import { EVMTx } from "../../../../chain/modules/EVMTransactions";
|
|
8
|
+
/**
|
|
9
|
+
* Commitment payload for txid-based bitcoin claims.
|
|
10
|
+
*
|
|
11
|
+
* @category Internal/Handlers
|
|
12
|
+
*/
|
|
8
13
|
export type BitcoinTxIdCommitmentData = {
|
|
9
14
|
txId: string;
|
|
10
15
|
};
|
|
@@ -7,10 +7,20 @@ import { EVMBtcStoredHeader } from "../../../../btcrelay/headers/EVMBtcStoredHea
|
|
|
7
7
|
import { EVMTx } from "../../../../chain/modules/EVMTransactions";
|
|
8
8
|
import { Buffer } from "buffer";
|
|
9
9
|
import { EVMSwapData } from "../../../EVMSwapData";
|
|
10
|
+
/**
|
|
11
|
+
* Common commitment fields used by all bitcoin-based claim handlers.
|
|
12
|
+
*
|
|
13
|
+
* @category Internal/Handlers
|
|
14
|
+
*/
|
|
10
15
|
export type BitcoinCommitmentData = {
|
|
11
16
|
btcRelay: EVMBtcRelay<any>;
|
|
12
17
|
confirmations: number;
|
|
13
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Common witness input for bitcoin-based claim handlers.
|
|
21
|
+
*
|
|
22
|
+
* @category Internal/Handlers
|
|
23
|
+
*/
|
|
14
24
|
export type BitcoinWitnessData = {
|
|
15
25
|
tx: {
|
|
16
26
|
blockhash: string;
|
|
@@ -24,6 +34,11 @@ export type BitcoinWitnessData = {
|
|
|
24
34
|
commitedHeader?: EVMBtcStoredHeader;
|
|
25
35
|
synchronizer?: RelaySynchronizer<EVMBtcStoredHeader, EVMTx, any>;
|
|
26
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Shared base implementation for bitcoin-backed claim handlers.
|
|
39
|
+
*
|
|
40
|
+
* @category Internal/Handlers
|
|
41
|
+
*/
|
|
27
42
|
export declare abstract class IBitcoinClaimHandler<C, W extends BitcoinWitnessData> implements IClaimHandler<C & BitcoinCommitmentData, W> {
|
|
28
43
|
readonly address: string;
|
|
29
44
|
constructor(address: string);
|
|
@@ -7,6 +7,11 @@ const Utils_1 = require("../../../../../utils/Utils");
|
|
|
7
7
|
const ethers_1 = require("ethers");
|
|
8
8
|
const buffer_1 = require("buffer");
|
|
9
9
|
const logger = (0, Utils_1.getLogger)("IBitcoinClaimHandler: ");
|
|
10
|
+
/**
|
|
11
|
+
* Shared base implementation for bitcoin-backed claim handlers.
|
|
12
|
+
*
|
|
13
|
+
* @category Internal/Handlers
|
|
14
|
+
*/
|
|
10
15
|
class IBitcoinClaimHandler {
|
|
11
16
|
constructor(address) {
|
|
12
17
|
this.address = address;
|
|
@@ -14,7 +19,7 @@ class IBitcoinClaimHandler {
|
|
|
14
19
|
serializeCommitment(data) {
|
|
15
20
|
const buffer = buffer_1.Buffer.alloc(24);
|
|
16
21
|
buffer.writeUint32BE(data.confirmations, 0);
|
|
17
|
-
buffer_1.Buffer.from(data.btcRelay.
|
|
22
|
+
buffer_1.Buffer.from(data.btcRelay._contractAddress.substring(2), "hex").copy(buffer, 4, 0, 20);
|
|
18
23
|
return buffer;
|
|
19
24
|
}
|
|
20
25
|
getCommitment(data) {
|
|
@@ -29,7 +34,7 @@ class IBitcoinClaimHandler {
|
|
|
29
34
|
const commitmentHash = (0, ethers_1.keccak256)(serializedCommitment);
|
|
30
35
|
if (!swapData.isClaimData(commitmentHash))
|
|
31
36
|
throw new Error("Invalid commit data");
|
|
32
|
-
const merkleProof = await btcRelay.
|
|
37
|
+
const merkleProof = await btcRelay._bitcoinRpc.getMerkleProof(tx.txid, tx.blockhash);
|
|
33
38
|
if (merkleProof == null)
|
|
34
39
|
throw new Error(`Failed to generate merkle proof for tx: ${tx.txid}!`);
|
|
35
40
|
logger.debug("getWitness(): merkle proof computed: ", merkleProof);
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { IntermediaryReputationType } from "@atomiqlabs/base";
|
|
2
2
|
import { EVMSwapModule } from "../EVMSwapModule";
|
|
3
3
|
import { EVMTx } from "../../chain/modules/EVMTransactions";
|
|
4
|
+
/**
|
|
5
|
+
* LP vault helper for intermediary balances, reputation and LP deposit/withdraw transactions.
|
|
6
|
+
*
|
|
7
|
+
* @category Internal/Swaps
|
|
8
|
+
*/
|
|
4
9
|
export declare class EVMLpVault extends EVMSwapModule {
|
|
5
10
|
private static readonly GasCosts;
|
|
6
11
|
/**
|
|
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EVMLpVault = void 0;
|
|
4
4
|
const EVMSwapModule_1 = require("../EVMSwapModule");
|
|
5
5
|
const EVMFees_1 = require("../../chain/modules/EVMFees");
|
|
6
|
+
/**
|
|
7
|
+
* LP vault helper for intermediary balances, reputation and LP deposit/withdraw transactions.
|
|
8
|
+
*
|
|
9
|
+
* @category Internal/Swaps
|
|
10
|
+
*/
|
|
6
11
|
class EVMLpVault extends EVMSwapModule_1.EVMSwapModule {
|
|
7
12
|
/**
|
|
8
13
|
* Action for withdrawing funds from the LP vault
|
|
@@ -57,13 +62,13 @@ class EVMLpVault extends EVMSwapModule_1.EVMSwapModule {
|
|
|
57
62
|
* @param token
|
|
58
63
|
*/
|
|
59
64
|
async getIntermediaryReputation(address, token) {
|
|
60
|
-
const filter = Object.keys(this.contract.
|
|
65
|
+
const filter = Object.keys(this.contract._claimHandlersByAddress).map(claimHandler => ({ owner: address, token, claimHandler }));
|
|
61
66
|
const resp = await this.swapContract.getReputation(filter);
|
|
62
67
|
if (resp.length !== filter.length)
|
|
63
68
|
throw new Error("getIntermediaryReputation(): Invalid response length");
|
|
64
69
|
const result = {};
|
|
65
|
-
Object.keys(this.contract.
|
|
66
|
-
const handler = this.contract.
|
|
70
|
+
Object.keys(this.contract._claimHandlersByAddress).forEach((address, index) => {
|
|
71
|
+
const handler = this.contract._claimHandlersByAddress[address.toLowerCase()];
|
|
67
72
|
const handlerResp = resp[index];
|
|
68
73
|
result[handler.getType()] = {
|
|
69
74
|
successVolume: handlerResp[0].amount,
|
|
@@ -117,7 +122,7 @@ class EVMLpVault extends EVMSwapModule_1.EVMSwapModule {
|
|
|
117
122
|
const txs = [];
|
|
118
123
|
//Approve first
|
|
119
124
|
if (token.toLowerCase() !== this.root.getNativeCurrencyAddress().toLowerCase()) {
|
|
120
|
-
const approveTx = await this.root.Tokens.checkAndGetApproveTx(signer, token, amount, this.contract.
|
|
125
|
+
const approveTx = await this.root.Tokens.checkAndGetApproveTx(signer, token, amount, this.contract._contractAddress, feeRate);
|
|
121
126
|
if (approveTx != null)
|
|
122
127
|
txs.push(approveTx);
|
|
123
128
|
}
|
|
@@ -3,6 +3,11 @@ import { EVMSwapModule } from "../EVMSwapModule";
|
|
|
3
3
|
import { EVMSwapData } from "../EVMSwapData";
|
|
4
4
|
import { EVMTx } from "../../chain/modules/EVMTransactions";
|
|
5
5
|
import { EVMBtcStoredHeader } from "../../btcrelay/headers/EVMBtcStoredHeader";
|
|
6
|
+
/**
|
|
7
|
+
* Swap claim helper for HTLC and BTC on-chain claim paths.
|
|
8
|
+
*
|
|
9
|
+
* @category Internal/Swaps
|
|
10
|
+
*/
|
|
6
11
|
export declare class EVMSwapClaim extends EVMSwapModule {
|
|
7
12
|
private static readonly GasCosts;
|
|
8
13
|
/**
|
|
@@ -35,7 +40,7 @@ export declare class EVMSwapClaim extends EVMSwapModule {
|
|
|
35
40
|
* @param tx bitcoin transaction that satisfies the swap condition
|
|
36
41
|
* @param requiredConfirmations
|
|
37
42
|
* @param vout vout of the bitcoin transaction that satisfies the swap condition
|
|
38
|
-
* @param commitedHeader
|
|
43
|
+
* @param commitedHeader committed header data from BTC relay (fetched internally if null)
|
|
39
44
|
* @param synchronizer optional synchronizer to use in case we need to sync up the btc relay ourselves
|
|
40
45
|
* @param feeRate fee rate to be used for the transactions
|
|
41
46
|
*/
|
|
@@ -48,7 +53,7 @@ export declare class EVMSwapClaim extends EVMSwapModule {
|
|
|
48
53
|
}, requiredConfirmations: number, vout: number, commitedHeader?: EVMBtcStoredHeader, synchronizer?: RelaySynchronizer<EVMBtcStoredHeader, EVMTx, any>, feeRate?: string): Promise<EVMTx[]>;
|
|
49
54
|
getClaimGas(swapData: EVMSwapData): number;
|
|
50
55
|
/**
|
|
51
|
-
*
|
|
56
|
+
* Returns the estimated fee of the claim transaction.
|
|
52
57
|
*/
|
|
53
58
|
getClaimFee(swapData: EVMSwapData, feeRate?: string): Promise<bigint>;
|
|
54
59
|
}
|
|
@@ -4,6 +4,11 @@ exports.EVMSwapClaim = void 0;
|
|
|
4
4
|
const base_1 = require("@atomiqlabs/base");
|
|
5
5
|
const EVMSwapModule_1 = require("../EVMSwapModule");
|
|
6
6
|
const EVMFees_1 = require("../../chain/modules/EVMFees");
|
|
7
|
+
/**
|
|
8
|
+
* Swap claim helper for HTLC and BTC on-chain claim paths.
|
|
9
|
+
*
|
|
10
|
+
* @category Internal/Swaps
|
|
11
|
+
*/
|
|
7
12
|
class EVMSwapClaim extends EVMSwapModule_1.EVMSwapModule {
|
|
8
13
|
/**
|
|
9
14
|
* Claim action which uses the provided witness for claiming the swap
|
|
@@ -38,7 +43,7 @@ class EVMSwapClaim extends EVMSwapModule_1.EVMSwapModule {
|
|
|
38
43
|
if (checkExpiry && await this.contract.isExpired(swapData.claimer.toString(), swapData)) {
|
|
39
44
|
throw new base_1.SwapDataVerificationError("Not enough time to reliably pay the invoice");
|
|
40
45
|
}
|
|
41
|
-
const claimHandler = this.contract.
|
|
46
|
+
const claimHandler = this.contract._claimHandlersByAddress[swapData.claimHandler.toLowerCase()];
|
|
42
47
|
if (claimHandler == null)
|
|
43
48
|
throw new base_1.SwapDataVerificationError("Unknown claim handler!");
|
|
44
49
|
if (claimHandler.getType() !== base_1.ChainSwapType.HTLC)
|
|
@@ -57,12 +62,12 @@ class EVMSwapClaim extends EVMSwapModule_1.EVMSwapModule {
|
|
|
57
62
|
* @param tx bitcoin transaction that satisfies the swap condition
|
|
58
63
|
* @param requiredConfirmations
|
|
59
64
|
* @param vout vout of the bitcoin transaction that satisfies the swap condition
|
|
60
|
-
* @param commitedHeader
|
|
65
|
+
* @param commitedHeader committed header data from BTC relay (fetched internally if null)
|
|
61
66
|
* @param synchronizer optional synchronizer to use in case we need to sync up the btc relay ourselves
|
|
62
67
|
* @param feeRate fee rate to be used for the transactions
|
|
63
68
|
*/
|
|
64
69
|
async txsClaimWithTxData(signer, swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, feeRate) {
|
|
65
|
-
const claimHandler = this.contract.
|
|
70
|
+
const claimHandler = this.contract._claimHandlersByAddress[swapData.claimHandler.toLowerCase()];
|
|
66
71
|
if (claimHandler == null)
|
|
67
72
|
throw new base_1.SwapDataVerificationError("Unknown claim handler!");
|
|
68
73
|
if (claimHandler.getType() !== base_1.ChainSwapType.CHAIN_NONCED &&
|
|
@@ -75,7 +80,7 @@ class EVMSwapClaim extends EVMSwapModule_1.EVMSwapModule {
|
|
|
75
80
|
vout,
|
|
76
81
|
requiredConfirmations,
|
|
77
82
|
commitedHeader,
|
|
78
|
-
btcRelay: this.contract.
|
|
83
|
+
btcRelay: this.contract._btcRelay,
|
|
79
84
|
synchronizer,
|
|
80
85
|
}, feeRate);
|
|
81
86
|
const claimTx = await this.Claim(signer, swapData, witness, feeRate, claimHandler.getGas(swapData));
|
|
@@ -115,13 +120,13 @@ class EVMSwapClaim extends EVMSwapModule_1.EVMSwapModule {
|
|
|
115
120
|
return totalGas;
|
|
116
121
|
}
|
|
117
122
|
/**
|
|
118
|
-
*
|
|
123
|
+
* Returns the estimated fee of the claim transaction.
|
|
119
124
|
*/
|
|
120
125
|
async getClaimFee(swapData, feeRate) {
|
|
121
126
|
feeRate ?? (feeRate = await this.root.Fees.getFeeRate());
|
|
122
127
|
//TODO: Claim with success action not supported yet!
|
|
123
128
|
let gasRequired = this.getClaimGas(swapData);
|
|
124
|
-
const claimHandler = this.contract.
|
|
129
|
+
const claimHandler = this.contract._claimHandlersByAddress[swapData.claimHandler.toLowerCase()];
|
|
125
130
|
if (claimHandler != null)
|
|
126
131
|
gasRequired += claimHandler.getGas(swapData);
|
|
127
132
|
return EVMFees_1.EVMFees.getGasFee(gasRequired, feeRate);
|
|
@@ -2,9 +2,19 @@ import { EVMSwapModule } from "../EVMSwapModule";
|
|
|
2
2
|
import { EVMSwapData } from "../EVMSwapData";
|
|
3
3
|
import { EVMSigner } from "../../wallet/EVMSigner";
|
|
4
4
|
import { EVMTx } from "../../chain/modules/EVMTransactions";
|
|
5
|
+
/**
|
|
6
|
+
* Prefetched values used for initialization signature verification.
|
|
7
|
+
*
|
|
8
|
+
* @category Internal/Swaps
|
|
9
|
+
*/
|
|
5
10
|
export type EVMPreFetchVerification = {
|
|
6
11
|
safeBlockTime: number;
|
|
7
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Swap initialization helper handling authorization signatures and init transaction construction.
|
|
15
|
+
*
|
|
16
|
+
* @category Internal/Swaps
|
|
17
|
+
*/
|
|
8
18
|
export declare class EVMSwapInit extends EVMSwapModule {
|
|
9
19
|
private static readonly GasCosts;
|
|
10
20
|
/**
|
|
@@ -25,6 +25,11 @@ const Initialize = [
|
|
|
25
25
|
{ name: "deadline", type: "uint256" },
|
|
26
26
|
{ name: "extraDataHash", type: "bytes32" }
|
|
27
27
|
];
|
|
28
|
+
/**
|
|
29
|
+
* Swap initialization helper handling authorization signatures and init transaction construction.
|
|
30
|
+
*
|
|
31
|
+
* @category Internal/Swaps
|
|
32
|
+
*/
|
|
28
33
|
class EVMSwapInit extends EVMSwapModule_1.EVMSwapModule {
|
|
29
34
|
/**
|
|
30
35
|
* bare Init action based on the data passed in swapData
|
|
@@ -63,7 +68,7 @@ class EVMSwapInit extends EVMSwapModule_1.EVMSwapModule {
|
|
|
63
68
|
}
|
|
64
69
|
async preFetchForInitSignatureVerification() {
|
|
65
70
|
return {
|
|
66
|
-
safeBlockTime: await this.root.Blocks.getBlockTime(this.root.
|
|
71
|
+
safeBlockTime: await this.root.Blocks.getBlockTime(this.root._config.safeBlockTag)
|
|
67
72
|
};
|
|
68
73
|
}
|
|
69
74
|
/**
|
|
@@ -77,7 +82,7 @@ class EVMSwapInit extends EVMSwapModule_1.EVMSwapModule {
|
|
|
77
82
|
*/
|
|
78
83
|
async signSwapInitialization(signer, swapData, authorizationTimeout) {
|
|
79
84
|
const authExpiry = Math.floor(Date.now() / 1000) + authorizationTimeout;
|
|
80
|
-
const signature = await this.root.Signatures.signTypedMessage(this.contract.
|
|
85
|
+
const signature = await this.root.Signatures.signTypedMessage(this.contract._contractAddress, signer, Initialize, "Initialize", {
|
|
81
86
|
"swapHash": "0x" + swapData.getEscrowHash(),
|
|
82
87
|
"offerer": swapData.offerer,
|
|
83
88
|
"claimer": swapData.claimer,
|
|
@@ -125,12 +130,12 @@ class EVMSwapInit extends EVMSwapModule_1.EVMSwapModule {
|
|
|
125
130
|
throw new base_1.SignatureVerificationError("Invalid prefix");
|
|
126
131
|
const currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
|
|
127
132
|
const timeoutBN = BigInt(timeout);
|
|
128
|
-
const isExpired = (timeoutBN - currentTimestamp) < BigInt(this.contract.
|
|
133
|
+
const isExpired = (timeoutBN - currentTimestamp) < BigInt(this.contract._authGracePeriod);
|
|
129
134
|
if (isExpired)
|
|
130
135
|
throw new base_1.SignatureVerificationError("Authorization expired!");
|
|
131
136
|
if (await this.isSignatureExpired(timeout, preFetchData))
|
|
132
137
|
throw new base_1.SignatureVerificationError("Authorization expired!");
|
|
133
|
-
const valid = await this.root.Signatures.isValidSignature(this.contract.
|
|
138
|
+
const valid = await this.root.Signatures.isValidSignature(this.contract._contractAddress, signature, signer, Initialize, "Initialize", {
|
|
134
139
|
"swapHash": "0x" + swapData.getEscrowHash(),
|
|
135
140
|
"offerer": swapData.offerer,
|
|
136
141
|
"claimer": swapData.claimer,
|
|
@@ -162,7 +167,7 @@ class EVMSwapInit extends EVMSwapModule_1.EVMSwapModule {
|
|
|
162
167
|
*/
|
|
163
168
|
async getSignatureExpiry(timeout) {
|
|
164
169
|
const now = Date.now();
|
|
165
|
-
const timeoutExpiryTime = (parseInt(timeout) - this.contract.
|
|
170
|
+
const timeoutExpiryTime = (parseInt(timeout) - this.contract._authGracePeriod) * 1000;
|
|
166
171
|
if (timeoutExpiryTime < now)
|
|
167
172
|
return 0;
|
|
168
173
|
return timeoutExpiryTime;
|
|
@@ -220,7 +225,7 @@ class EVMSwapInit extends EVMSwapModule_1.EVMSwapModule {
|
|
|
220
225
|
requiredApprovals[swapData.depositToken.toLowerCase()] += swapData.getTotalDeposit();
|
|
221
226
|
}
|
|
222
227
|
}
|
|
223
|
-
const requiredApprovalTxns = await Promise.all(Object.keys(requiredApprovals).map(token => this.root.Tokens.checkAndGetApproveTx(sender, token, requiredApprovals[token], this.contract.
|
|
228
|
+
const requiredApprovalTxns = await Promise.all(Object.keys(requiredApprovals).map(token => this.root.Tokens.checkAndGetApproveTx(sender, token, requiredApprovals[token], this.contract._contractAddress, feeRate)));
|
|
224
229
|
requiredApprovalTxns.forEach(tx => tx != null && txs.push(tx));
|
|
225
230
|
txs.push(await this.Init(sender, swapData, BigInt(timeout), signature ?? "0x", feeRate));
|
|
226
231
|
this.logger.debug("txsInitPayIn(): create swap init TX, swap: " + swapData.getClaimHash() +
|
|
@@ -2,6 +2,11 @@ import { EVMSwapModule } from "../EVMSwapModule";
|
|
|
2
2
|
import { EVMSwapData } from "../EVMSwapData";
|
|
3
3
|
import { EVMSigner } from "../../wallet/EVMSigner";
|
|
4
4
|
import { EVMTx } from "../../chain/modules/EVMTransactions";
|
|
5
|
+
/**
|
|
6
|
+
* Swap refund helper for timeout and cooperative refund flows.
|
|
7
|
+
*
|
|
8
|
+
* @category Internal/Swaps
|
|
9
|
+
*/
|
|
5
10
|
export declare class EVMSwapRefund extends EVMSwapModule {
|
|
6
11
|
private static readonly GasCosts;
|
|
7
12
|
/**
|
|
@@ -8,6 +8,11 @@ const Refund = [
|
|
|
8
8
|
{ name: "swapHash", type: "bytes32" },
|
|
9
9
|
{ name: "timeout", type: "uint256" }
|
|
10
10
|
];
|
|
11
|
+
/**
|
|
12
|
+
* Swap refund helper for timeout and cooperative refund flows.
|
|
13
|
+
*
|
|
14
|
+
* @category Internal/Swaps
|
|
15
|
+
*/
|
|
11
16
|
class EVMSwapRefund extends EVMSwapModule_1.EVMSwapModule {
|
|
12
17
|
/**
|
|
13
18
|
* Action for generic Refund instruction
|
|
@@ -44,7 +49,7 @@ class EVMSwapRefund extends EVMSwapModule_1.EVMSwapModule {
|
|
|
44
49
|
async signSwapRefund(signer, swapData, authorizationTimeout) {
|
|
45
50
|
const authPrefix = "refund";
|
|
46
51
|
const authTimeout = Math.floor(Date.now() / 1000) + authorizationTimeout;
|
|
47
|
-
const signature = await this.root.Signatures.signTypedMessage(this.contract.
|
|
52
|
+
const signature = await this.root.Signatures.signTypedMessage(this.contract._contractAddress, signer, Refund, "Refund", {
|
|
48
53
|
"swapHash": "0x" + swapData.getEscrowHash(),
|
|
49
54
|
"timeout": BigInt(authTimeout)
|
|
50
55
|
});
|
|
@@ -59,10 +64,10 @@ class EVMSwapRefund extends EVMSwapModule_1.EVMSwapModule {
|
|
|
59
64
|
throw new base_1.SignatureVerificationError("Invalid prefix");
|
|
60
65
|
const expiryTimestamp = BigInt(timeout);
|
|
61
66
|
const currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
|
|
62
|
-
const isExpired = (expiryTimestamp - currentTimestamp) < BigInt(this.contract.
|
|
67
|
+
const isExpired = (expiryTimestamp - currentTimestamp) < BigInt(this.contract._authGracePeriod);
|
|
63
68
|
if (isExpired)
|
|
64
69
|
throw new base_1.SignatureVerificationError("Authorization expired!");
|
|
65
|
-
const valid = await this.root.Signatures.isValidSignature(this.contract.
|
|
70
|
+
const valid = await this.root.Signatures.isValidSignature(this.contract._contractAddress, signature, swapData.claimer, Refund, "Refund", {
|
|
66
71
|
"swapHash": "0x" + swapData.getEscrowHash(),
|
|
67
72
|
"timeout": BigInt(expiryTimestamp)
|
|
68
73
|
});
|
|
@@ -81,7 +86,7 @@ class EVMSwapRefund extends EVMSwapModule_1.EVMSwapModule {
|
|
|
81
86
|
* @param witnessData
|
|
82
87
|
*/
|
|
83
88
|
async txsRefund(signer, swapData, check, feeRate, witnessData) {
|
|
84
|
-
const refundHandler = this.contract.
|
|
89
|
+
const refundHandler = this.contract._refundHandlersByAddress[swapData.refundHandler.toLowerCase()];
|
|
85
90
|
if (refundHandler == null)
|
|
86
91
|
throw new Error("Invalid refund handler");
|
|
87
92
|
if (check && !await this.contract.isRequestRefundable(swapData.offerer.toString(), swapData)) {
|
|
@@ -1,10 +1,30 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
1
3
|
import { Signer, TransactionRequest, TransactionResponse } from "ethers";
|
|
2
4
|
import { EVMSigner } from "./EVMSigner";
|
|
3
5
|
/**
|
|
4
|
-
* Browser-based EVM signer for external
|
|
6
|
+
* Browser-based EVM signer, intended for injected/external wallets. This ensures no explicit
|
|
7
|
+
* `signTransaction()` flow is required and transaction submission goes through `sendTransaction()`.
|
|
8
|
+
*
|
|
5
9
|
* @category Wallets
|
|
6
10
|
*/
|
|
7
11
|
export declare class EVMBrowserSigner extends EVMSigner {
|
|
8
|
-
|
|
12
|
+
private usesECDSADN?;
|
|
13
|
+
getReproducibleEntropy?: (appName: string) => Promise<Buffer>;
|
|
14
|
+
/**
|
|
15
|
+
* @param account Signer account to request signatures and send transaction through
|
|
16
|
+
* @param address Signer address
|
|
17
|
+
* @param usesECDSADN Optional flag indicating whether the signer supports signing using ECDSA-DN (deterministic
|
|
18
|
+
* nonce) algorithm, this allows the wallet to produce reproducible entropy. Only pass `true` here if you are
|
|
19
|
+
* 100% sure that the signer supports this!
|
|
20
|
+
*/
|
|
21
|
+
constructor(account: Signer, address: string, usesECDSADN?: boolean);
|
|
22
|
+
/**
|
|
23
|
+
* Signs and sends the provided EVM transaction.
|
|
24
|
+
* Maps common wallet rejection errors to a consistent user-facing message.
|
|
25
|
+
*
|
|
26
|
+
* @param transaction A transaction to sign and send
|
|
27
|
+
* @param onBeforePublish Optional callback called after signing and before broadcast when available
|
|
28
|
+
*/
|
|
9
29
|
sendTransaction(transaction: TransactionRequest, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<TransactionResponse>;
|
|
10
30
|
}
|
|
@@ -1,16 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EVMBrowserSigner = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
4
5
|
const EVMSigner_1 = require("./EVMSigner");
|
|
5
6
|
/**
|
|
6
|
-
* Browser-based EVM signer for external
|
|
7
|
+
* Browser-based EVM signer, intended for injected/external wallets. This ensures no explicit
|
|
8
|
+
* `signTransaction()` flow is required and transaction submission goes through `sendTransaction()`.
|
|
9
|
+
*
|
|
7
10
|
* @category Wallets
|
|
8
11
|
*/
|
|
9
12
|
class EVMBrowserSigner extends EVMSigner_1.EVMSigner {
|
|
10
|
-
|
|
13
|
+
/**
|
|
14
|
+
* @param account Signer account to request signatures and send transaction through
|
|
15
|
+
* @param address Signer address
|
|
16
|
+
* @param usesECDSADN Optional flag indicating whether the signer supports signing using ECDSA-DN (deterministic
|
|
17
|
+
* nonce) algorithm, this allows the wallet to produce reproducible entropy. Only pass `true` here if you are
|
|
18
|
+
* 100% sure that the signer supports this!
|
|
19
|
+
*/
|
|
20
|
+
constructor(account, address, usesECDSADN) {
|
|
11
21
|
super(account, address, false);
|
|
22
|
+
this.usesECDSADN = usesECDSADN;
|
|
12
23
|
this.signTransaction = undefined;
|
|
24
|
+
if (this.usesECDSADN !== false) {
|
|
25
|
+
this.getReproducibleEntropy = async (appName) => {
|
|
26
|
+
if (this.usesECDSADN === false)
|
|
27
|
+
throw new Error("This wallet doesn't support generating recoverable entropy!");
|
|
28
|
+
const message = EVMSigner_1.EVMSigner.getReproducibleEntropyMessage(appName);
|
|
29
|
+
const signature = await account.signMessage(message);
|
|
30
|
+
if (this.usesECDSADN !== true) {
|
|
31
|
+
const secondSignature = await account.signMessage(message);
|
|
32
|
+
if (signature !== secondSignature) {
|
|
33
|
+
this.usesECDSADN = false;
|
|
34
|
+
this.getReproducibleEntropy = undefined;
|
|
35
|
+
throw new Error("This wallet doesn't support generating recoverable entropy!");
|
|
36
|
+
}
|
|
37
|
+
this.usesECDSADN = true;
|
|
38
|
+
}
|
|
39
|
+
if ((0, ethers_1.verifyMessage)(message, signature) !== address)
|
|
40
|
+
throw new Error("Invalid wallet signature provided!");
|
|
41
|
+
return Buffer.from(signature.substring(2), "hex");
|
|
42
|
+
};
|
|
43
|
+
}
|
|
13
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Signs and sends the provided EVM transaction.
|
|
47
|
+
* Maps common wallet rejection errors to a consistent user-facing message.
|
|
48
|
+
*
|
|
49
|
+
* @param transaction A transaction to sign and send
|
|
50
|
+
* @param onBeforePublish Optional callback called after signing and before broadcast when available
|
|
51
|
+
*/
|
|
14
52
|
async sendTransaction(transaction, onBeforePublish) {
|
|
15
53
|
try {
|
|
16
54
|
return await super.sendTransaction(transaction, onBeforePublish);
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { Signer, TransactionRequest, TransactionResponse } from "ethers";
|
|
2
|
-
import { EVMBlockTag } from "../chain/modules/EVMBlocks";
|
|
3
2
|
import { EVMChainInterface } from "../chain/EVMChainInterface";
|
|
4
3
|
import { EVMSigner } from "./EVMSigner";
|
|
4
|
+
/**
|
|
5
|
+
* A robust EVM signer implementation with internal nonce management, automatic rebroadcasting and fee bumping.
|
|
6
|
+
* Uses Node.js `fs` to persist transaction data across restarts, so it is intended for backend runtimes.
|
|
7
|
+
*
|
|
8
|
+
* @category Wallets
|
|
9
|
+
*/
|
|
5
10
|
export declare class EVMPersistentSigner extends EVMSigner {
|
|
6
|
-
readonly safeBlockTag
|
|
11
|
+
private readonly safeBlockTag;
|
|
7
12
|
private pendingTxs;
|
|
8
13
|
private confirmedNonce;
|
|
9
14
|
private pendingNonce;
|
|
@@ -23,7 +28,13 @@ export declare class EVMPersistentSigner extends EVMSigner {
|
|
|
23
28
|
private checkPastTransactions;
|
|
24
29
|
private startFeeBumper;
|
|
25
30
|
private syncNonceFromChain;
|
|
31
|
+
/**
|
|
32
|
+
* @inheritDoc
|
|
33
|
+
*/
|
|
26
34
|
init(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* @inheritDoc
|
|
37
|
+
*/
|
|
27
38
|
stop(): Promise<void>;
|
|
28
39
|
private readonly sendTransactionQueue;
|
|
29
40
|
sendTransaction(transaction: TransactionRequest, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<TransactionResponse>;
|
|
@@ -10,6 +10,12 @@ const fs = require("fs/promises");
|
|
|
10
10
|
const WAIT_BEFORE_BUMP = 15 * 1000;
|
|
11
11
|
const MIN_FEE_INCREASE_ABSOLUTE = 1n * 1000000000n; //1GWei
|
|
12
12
|
const MIN_FEE_INCREASE_PPM = 100000n; // +10%
|
|
13
|
+
/**
|
|
14
|
+
* A robust EVM signer implementation with internal nonce management, automatic rebroadcasting and fee bumping.
|
|
15
|
+
* Uses Node.js `fs` to persist transaction data across restarts, so it is intended for backend runtimes.
|
|
16
|
+
*
|
|
17
|
+
* @category Wallets
|
|
18
|
+
*/
|
|
13
19
|
class EVMPersistentSigner extends EVMSigner_1.EVMSigner {
|
|
14
20
|
constructor(account, address, chainInterface, directory, minFeeIncreaseAbsolute, minFeeIncreasePpm, waitBeforeBumpMillis) {
|
|
15
21
|
super(account, address, true);
|
|
@@ -25,7 +31,7 @@ class EVMPersistentSigner extends EVMSigner_1.EVMSigner {
|
|
|
25
31
|
this.minFeeIncreaseAbsolute = minFeeIncreaseAbsolute ?? MIN_FEE_INCREASE_ABSOLUTE;
|
|
26
32
|
this.minFeeIncreasePpm = minFeeIncreasePpm ?? MIN_FEE_INCREASE_PPM;
|
|
27
33
|
this.waitBeforeBump = waitBeforeBumpMillis ?? WAIT_BEFORE_BUMP;
|
|
28
|
-
this.safeBlockTag = chainInterface.
|
|
34
|
+
this.safeBlockTag = chainInterface._config.safeBlockTag;
|
|
29
35
|
this.logger = (0, Utils_1.getLogger)("EVMPersistentSigner(" + address + "): ");
|
|
30
36
|
}
|
|
31
37
|
async load() {
|
|
@@ -179,6 +185,9 @@ class EVMPersistentSigner extends EVMSigner_1.EVMSigner {
|
|
|
179
185
|
this.save();
|
|
180
186
|
}
|
|
181
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* @inheritDoc
|
|
190
|
+
*/
|
|
182
191
|
async init() {
|
|
183
192
|
try {
|
|
184
193
|
await fs.mkdir(this.directory);
|
|
@@ -190,6 +199,9 @@ class EVMPersistentSigner extends EVMSigner_1.EVMSigner {
|
|
|
190
199
|
await this.load();
|
|
191
200
|
this.startFeeBumper();
|
|
192
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* @inheritDoc
|
|
204
|
+
*/
|
|
193
205
|
stop() {
|
|
194
206
|
this.stopped = true;
|
|
195
207
|
if (this.feeBumper != null) {
|
|
@@ -1,19 +1,48 @@
|
|
|
1
1
|
import { AbstractSigner } from "@atomiqlabs/base";
|
|
2
2
|
import { Signer, TransactionRequest, TransactionResponse } from "ethers";
|
|
3
3
|
/**
|
|
4
|
-
* EVM signer implementation wrapping an ethers Signer
|
|
4
|
+
* EVM signer implementation wrapping an ethers {@link Signer}, for browser-based wallet use
|
|
5
|
+
* {@link EVMBrowserSigner}.
|
|
6
|
+
*
|
|
5
7
|
* @category Wallets
|
|
6
8
|
*/
|
|
7
9
|
export declare class EVMSigner implements AbstractSigner {
|
|
10
|
+
/**
|
|
11
|
+
* A static message, which should be signed by the EVM wallets to generate reproducible entropy. Works when
|
|
12
|
+
* wallets use signing with deterministic nonce, such that signature over the same message always yields the
|
|
13
|
+
* same signature (same entropy).
|
|
14
|
+
*/
|
|
15
|
+
private static readonly EVM_REPRODUCIBLE_ENTROPY_MESSAGE;
|
|
16
|
+
/**
|
|
17
|
+
* Returns a static message, which should be signed by the EVM wallets to generate reproducible entropy. Works when
|
|
18
|
+
* wallets use signing with deterministic nonce, such that signature over the same message always yields the
|
|
19
|
+
* same signature (same entropy).
|
|
20
|
+
*
|
|
21
|
+
* @param appName Application name to differentiate reproducible entropy generated across different apps
|
|
22
|
+
*/
|
|
23
|
+
static getReproducibleEntropyMessage(appName: string): string;
|
|
8
24
|
type: "AtomiqAbstractSigner";
|
|
9
25
|
account: Signer;
|
|
10
26
|
readonly address: string;
|
|
11
27
|
readonly isManagingNoncesInternally: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Constructs a signer wrapping an ethers {@link Signer}.
|
|
30
|
+
*
|
|
31
|
+
* @param account
|
|
32
|
+
* @param address
|
|
33
|
+
* @param isManagingNoncesInternally
|
|
34
|
+
*/
|
|
12
35
|
constructor(account: Signer, address: string, isManagingNoncesInternally?: boolean);
|
|
13
36
|
/**
|
|
14
37
|
* @inheritDoc
|
|
15
38
|
*/
|
|
16
39
|
getAddress(): string;
|
|
40
|
+
/**
|
|
41
|
+
* @inheritDoc
|
|
42
|
+
*/
|
|
17
43
|
signTransaction?(transaction: TransactionRequest): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* @inheritDoc
|
|
46
|
+
*/
|
|
18
47
|
sendTransaction(transaction: TransactionRequest, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<TransactionResponse>;
|
|
19
48
|
}
|