@atomiqlabs/chain-evm 1.0.0-dev.22
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/LICENSE +201 -0
- package/dist/chains/citrea/CitreaChainType.d.ts +13 -0
- package/dist/chains/citrea/CitreaChainType.js +2 -0
- package/dist/chains/citrea/CitreaInitializer.d.ts +30 -0
- package/dist/chains/citrea/CitreaInitializer.js +120 -0
- package/dist/evm/btcrelay/BtcRelayAbi.d.ts +198 -0
- package/dist/evm/btcrelay/BtcRelayAbi.js +261 -0
- package/dist/evm/btcrelay/BtcRelayTypechain.d.ts +172 -0
- package/dist/evm/btcrelay/BtcRelayTypechain.js +2 -0
- package/dist/evm/btcrelay/EVMBtcRelay.d.ts +188 -0
- package/dist/evm/btcrelay/EVMBtcRelay.js +419 -0
- package/dist/evm/btcrelay/headers/EVMBtcHeader.d.ts +33 -0
- package/dist/evm/btcrelay/headers/EVMBtcHeader.js +84 -0
- package/dist/evm/btcrelay/headers/EVMBtcStoredHeader.d.ts +56 -0
- package/dist/evm/btcrelay/headers/EVMBtcStoredHeader.js +123 -0
- package/dist/evm/chain/EVMChainInterface.d.ts +51 -0
- package/dist/evm/chain/EVMChainInterface.js +90 -0
- package/dist/evm/chain/EVMModule.d.ts +9 -0
- package/dist/evm/chain/EVMModule.js +13 -0
- package/dist/evm/chain/modules/ERC20Abi.d.ts +168 -0
- package/dist/evm/chain/modules/ERC20Abi.js +225 -0
- package/dist/evm/chain/modules/EVMAddresses.d.ts +9 -0
- package/dist/evm/chain/modules/EVMAddresses.js +26 -0
- package/dist/evm/chain/modules/EVMBlocks.d.ts +20 -0
- package/dist/evm/chain/modules/EVMBlocks.js +64 -0
- package/dist/evm/chain/modules/EVMEvents.d.ts +36 -0
- package/dist/evm/chain/modules/EVMEvents.js +122 -0
- package/dist/evm/chain/modules/EVMFees.d.ts +35 -0
- package/dist/evm/chain/modules/EVMFees.js +73 -0
- package/dist/evm/chain/modules/EVMSignatures.d.ts +29 -0
- package/dist/evm/chain/modules/EVMSignatures.js +68 -0
- package/dist/evm/chain/modules/EVMTokens.d.ts +49 -0
- package/dist/evm/chain/modules/EVMTokens.js +105 -0
- package/dist/evm/chain/modules/EVMTransactions.d.ts +89 -0
- package/dist/evm/chain/modules/EVMTransactions.js +216 -0
- package/dist/evm/contract/EVMContractBase.d.ts +22 -0
- package/dist/evm/contract/EVMContractBase.js +34 -0
- package/dist/evm/contract/EVMContractModule.d.ts +8 -0
- package/dist/evm/contract/EVMContractModule.js +11 -0
- package/dist/evm/contract/modules/EVMContractEvents.d.ts +42 -0
- package/dist/evm/contract/modules/EVMContractEvents.js +75 -0
- package/dist/evm/events/EVMChainEvents.d.ts +22 -0
- package/dist/evm/events/EVMChainEvents.js +67 -0
- package/dist/evm/events/EVMChainEventsBrowser.d.ts +86 -0
- package/dist/evm/events/EVMChainEventsBrowser.js +294 -0
- package/dist/evm/spv_swap/EVMSpvVaultContract.d.ts +64 -0
- package/dist/evm/spv_swap/EVMSpvVaultContract.js +410 -0
- package/dist/evm/spv_swap/EVMSpvVaultData.d.ts +38 -0
- package/dist/evm/spv_swap/EVMSpvVaultData.js +159 -0
- package/dist/evm/spv_swap/EVMSpvWithdrawalData.d.ts +19 -0
- package/dist/evm/spv_swap/EVMSpvWithdrawalData.js +55 -0
- package/dist/evm/spv_swap/SpvVaultContractAbi.d.ts +91 -0
- package/dist/evm/spv_swap/SpvVaultContractAbi.js +849 -0
- package/dist/evm/spv_swap/SpvVaultContractTypechain.d.ts +450 -0
- package/dist/evm/spv_swap/SpvVaultContractTypechain.js +2 -0
- package/dist/evm/swaps/EVMSwapContract.d.ts +192 -0
- package/dist/evm/swaps/EVMSwapContract.js +373 -0
- package/dist/evm/swaps/EVMSwapData.d.ts +64 -0
- package/dist/evm/swaps/EVMSwapData.js +254 -0
- package/dist/evm/swaps/EVMSwapModule.d.ts +9 -0
- package/dist/evm/swaps/EVMSwapModule.js +11 -0
- package/dist/evm/swaps/EscrowManagerAbi.d.ts +120 -0
- package/dist/evm/swaps/EscrowManagerAbi.js +985 -0
- package/dist/evm/swaps/EscrowManagerTypechain.d.ts +475 -0
- package/dist/evm/swaps/EscrowManagerTypechain.js +2 -0
- package/dist/evm/swaps/handlers/IHandler.d.ts +13 -0
- package/dist/evm/swaps/handlers/IHandler.js +2 -0
- package/dist/evm/swaps/handlers/claim/ClaimHandlers.d.ts +10 -0
- package/dist/evm/swaps/handlers/claim/ClaimHandlers.js +13 -0
- package/dist/evm/swaps/handlers/claim/HashlockClaimHandler.d.ts +20 -0
- package/dist/evm/swaps/handlers/claim/HashlockClaimHandler.js +39 -0
- package/dist/evm/swaps/handlers/claim/btc/BitcoinNoncedOutputClaimHandler.d.ts +24 -0
- package/dist/evm/swaps/handlers/claim/btc/BitcoinNoncedOutputClaimHandler.js +59 -0
- package/dist/evm/swaps/handlers/claim/btc/BitcoinOutputClaimHandler.d.ts +25 -0
- package/dist/evm/swaps/handlers/claim/btc/BitcoinOutputClaimHandler.js +51 -0
- package/dist/evm/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.d.ts +21 -0
- package/dist/evm/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.js +28 -0
- package/dist/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.d.ts +48 -0
- package/dist/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.js +63 -0
- package/dist/evm/swaps/handlers/refund/TimelockRefundHandler.d.ts +17 -0
- package/dist/evm/swaps/handlers/refund/TimelockRefundHandler.js +28 -0
- package/dist/evm/swaps/modules/EVMLpVault.d.ts +69 -0
- package/dist/evm/swaps/modules/EVMLpVault.js +131 -0
- package/dist/evm/swaps/modules/EVMSwapClaim.d.ts +53 -0
- package/dist/evm/swaps/modules/EVMSwapClaim.js +101 -0
- package/dist/evm/swaps/modules/EVMSwapInit.d.ts +88 -0
- package/dist/evm/swaps/modules/EVMSwapInit.js +241 -0
- package/dist/evm/swaps/modules/EVMSwapRefund.d.ts +62 -0
- package/dist/evm/swaps/modules/EVMSwapRefund.js +132 -0
- package/dist/evm/typechain/common.d.ts +50 -0
- package/dist/evm/typechain/common.js +2 -0
- package/dist/evm/wallet/EVMSigner.d.ts +9 -0
- package/dist/evm/wallet/EVMSigner.js +16 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +53 -0
- package/dist/utils/Utils.d.ts +15 -0
- package/dist/utils/Utils.js +71 -0
- package/package.json +37 -0
- package/src/chains/citrea/CitreaChainType.ts +28 -0
- package/src/chains/citrea/CitreaInitializer.ts +167 -0
- package/src/evm/btcrelay/BtcRelayAbi.ts +258 -0
- package/src/evm/btcrelay/BtcRelayTypechain.ts +371 -0
- package/src/evm/btcrelay/EVMBtcRelay.ts +517 -0
- package/src/evm/btcrelay/headers/EVMBtcHeader.ts +110 -0
- package/src/evm/btcrelay/headers/EVMBtcStoredHeader.ts +153 -0
- package/src/evm/chain/EVMChainInterface.ts +157 -0
- package/src/evm/chain/EVMModule.ts +21 -0
- package/src/evm/chain/modules/ERC20Abi.ts +222 -0
- package/src/evm/chain/modules/EVMAddresses.ts +24 -0
- package/src/evm/chain/modules/EVMBlocks.ts +75 -0
- package/src/evm/chain/modules/EVMEvents.ts +139 -0
- package/src/evm/chain/modules/EVMFees.ts +105 -0
- package/src/evm/chain/modules/EVMSignatures.ts +76 -0
- package/src/evm/chain/modules/EVMTokens.ts +115 -0
- package/src/evm/chain/modules/EVMTransactions.ts +246 -0
- package/src/evm/contract/EVMContractBase.ts +63 -0
- package/src/evm/contract/EVMContractModule.ts +16 -0
- package/src/evm/contract/modules/EVMContractEvents.ts +102 -0
- package/src/evm/events/EVMChainEvents.ts +81 -0
- package/src/evm/events/EVMChainEventsBrowser.ts +390 -0
- package/src/evm/spv_swap/EVMSpvVaultContract.ts +533 -0
- package/src/evm/spv_swap/EVMSpvVaultData.ts +201 -0
- package/src/evm/spv_swap/EVMSpvWithdrawalData.ts +70 -0
- package/src/evm/spv_swap/SpvVaultContractAbi.ts +846 -0
- package/src/evm/spv_swap/SpvVaultContractTypechain.ts +685 -0
- package/src/evm/swaps/EVMSwapContract.ts +590 -0
- package/src/evm/swaps/EVMSwapData.ts +367 -0
- package/src/evm/swaps/EVMSwapModule.ts +16 -0
- package/src/evm/swaps/EscrowManagerAbi.ts +982 -0
- package/src/evm/swaps/EscrowManagerTypechain.ts +723 -0
- package/src/evm/swaps/handlers/IHandler.ts +17 -0
- package/src/evm/swaps/handlers/claim/ClaimHandlers.ts +20 -0
- package/src/evm/swaps/handlers/claim/HashlockClaimHandler.ts +47 -0
- package/src/evm/swaps/handlers/claim/btc/BitcoinNoncedOutputClaimHandler.ts +82 -0
- package/src/evm/swaps/handlers/claim/btc/BitcoinOutputClaimHandler.ts +76 -0
- package/src/evm/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.ts +46 -0
- package/src/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.ts +115 -0
- package/src/evm/swaps/handlers/refund/TimelockRefundHandler.ts +38 -0
- package/src/evm/swaps/modules/EVMLpVault.ts +153 -0
- package/src/evm/swaps/modules/EVMSwapClaim.ts +141 -0
- package/src/evm/swaps/modules/EVMSwapInit.ts +292 -0
- package/src/evm/swaps/modules/EVMSwapRefund.ts +198 -0
- package/src/evm/typechain/common.ts +131 -0
- package/src/evm/wallet/EVMSigner.ts +23 -0
- package/src/index.ts +44 -0
- package/src/utils/Utils.ts +81 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EVMBtcStoredHeader = void 0;
|
|
4
|
+
const base_1 = require("@atomiqlabs/base");
|
|
5
|
+
const EVMBtcHeader_1 = require("./EVMBtcHeader");
|
|
6
|
+
const buffer_1 = require("buffer");
|
|
7
|
+
const ethers_1 = require("ethers");
|
|
8
|
+
class EVMBtcStoredHeader {
|
|
9
|
+
constructor(obj) {
|
|
10
|
+
this.blockheader = obj.blockheader instanceof EVMBtcHeader_1.EVMBtcHeader ? obj.blockheader : new EVMBtcHeader_1.EVMBtcHeader(obj.blockheader);
|
|
11
|
+
this.blockHash = obj.blockHash;
|
|
12
|
+
this.chainWork = obj.chainWork;
|
|
13
|
+
this.blockHeight = obj.blockHeight;
|
|
14
|
+
this.lastDiffAdjustment = obj.lastDiffAdjustment;
|
|
15
|
+
this.prevBlockTimestamps = obj.prevBlockTimestamps;
|
|
16
|
+
}
|
|
17
|
+
getBlockheight() {
|
|
18
|
+
return this.blockHeight;
|
|
19
|
+
}
|
|
20
|
+
getChainWork() {
|
|
21
|
+
return buffer_1.Buffer.from(this.chainWork.toString(16).padStart(64, "0"), "hex");
|
|
22
|
+
}
|
|
23
|
+
getHeader() {
|
|
24
|
+
return this.blockheader;
|
|
25
|
+
}
|
|
26
|
+
getLastDiffAdjustment() {
|
|
27
|
+
return this.lastDiffAdjustment;
|
|
28
|
+
}
|
|
29
|
+
getPrevBlockTimestamps() {
|
|
30
|
+
return this.prevBlockTimestamps;
|
|
31
|
+
}
|
|
32
|
+
getBlockHash() {
|
|
33
|
+
return buffer_1.Buffer.from([...this.blockHash]).reverse();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Computes prevBlockTimestamps for a next block, shifting the old block timestamps to the left & appending
|
|
37
|
+
* this block's timestamp to the end
|
|
38
|
+
*
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
computeNextBlockTimestamps() {
|
|
42
|
+
const prevBlockTimestamps = [...this.prevBlockTimestamps];
|
|
43
|
+
for (let i = 1; i < 10; i++) {
|
|
44
|
+
prevBlockTimestamps[i - 1] = prevBlockTimestamps[i];
|
|
45
|
+
}
|
|
46
|
+
prevBlockTimestamps[9] = this.blockheader.getTimestamp();
|
|
47
|
+
return prevBlockTimestamps;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Computes total chain work after a new header with "nbits" is added to the chain
|
|
51
|
+
*
|
|
52
|
+
* @param nbits
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
computeNextChainWork(nbits) {
|
|
56
|
+
return this.chainWork + base_1.BigIntBufferUtils.fromBuffer(base_1.StatePredictorUtils.getChainwork(nbits));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Computes lastDiffAdjustment, this changes only once every DIFF_ADJUSTMENT_PERIOD blocks
|
|
60
|
+
*
|
|
61
|
+
* @param headerTimestamp
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
computeNextLastDiffAdjustment(headerTimestamp) {
|
|
65
|
+
const blockheight = this.blockHeight + 1;
|
|
66
|
+
let lastDiffAdjustment = this.lastDiffAdjustment;
|
|
67
|
+
if (blockheight % base_1.StatePredictorUtils.DIFF_ADJUSTMENT_PERIOD === 0) {
|
|
68
|
+
lastDiffAdjustment = headerTimestamp;
|
|
69
|
+
}
|
|
70
|
+
return lastDiffAdjustment;
|
|
71
|
+
}
|
|
72
|
+
computeNext(header) {
|
|
73
|
+
header.previousBlockhash = this.blockHash;
|
|
74
|
+
return new EVMBtcStoredHeader({
|
|
75
|
+
chainWork: this.computeNextChainWork(header.getNbits()),
|
|
76
|
+
prevBlockTimestamps: this.computeNextBlockTimestamps(),
|
|
77
|
+
blockHeight: this.blockHeight + 1,
|
|
78
|
+
lastDiffAdjustment: this.computeNextLastDiffAdjustment(header.getTimestamp()),
|
|
79
|
+
blockHash: header.getHash(),
|
|
80
|
+
blockheader: header
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
getCommitHash() {
|
|
84
|
+
return (0, ethers_1.keccak256)(this.serialize());
|
|
85
|
+
}
|
|
86
|
+
serialize() {
|
|
87
|
+
const buffer = buffer_1.Buffer.alloc(160);
|
|
88
|
+
this.blockheader.serialize().copy(buffer, 0, 0, 80);
|
|
89
|
+
base_1.BigIntBufferUtils.toBuffer(this.chainWork, "be", 32).copy(buffer, 80, 0, 32);
|
|
90
|
+
buffer.writeUint32BE(this.blockHeight, 112);
|
|
91
|
+
buffer.writeUint32BE(this.lastDiffAdjustment, 116);
|
|
92
|
+
for (let i = 0; i < 10; i++) {
|
|
93
|
+
buffer.writeUint32BE(this.prevBlockTimestamps[i], 120 + (i * 4));
|
|
94
|
+
}
|
|
95
|
+
return buffer;
|
|
96
|
+
}
|
|
97
|
+
serializeToStruct() {
|
|
98
|
+
const buffer = this.serialize();
|
|
99
|
+
const result = [];
|
|
100
|
+
for (let i = 0; i < 5; i++) {
|
|
101
|
+
result[i] = "0x" + buffer.subarray(i * 32, (i + 1) * 32).toString("hex");
|
|
102
|
+
}
|
|
103
|
+
return { data: result };
|
|
104
|
+
}
|
|
105
|
+
static deserialize(data) {
|
|
106
|
+
if (data.length !== 160)
|
|
107
|
+
throw new Error(`Invalid size Expected 160, got: ${data.length}!`);
|
|
108
|
+
const blockheader = EVMBtcHeader_1.EVMBtcHeader.deserialize(data.subarray(0, 80));
|
|
109
|
+
const prevBlockTimestamps = [];
|
|
110
|
+
for (let i = 0; i < 10; i++) {
|
|
111
|
+
prevBlockTimestamps[i] = data.readUint32BE(120 + (i * 4));
|
|
112
|
+
}
|
|
113
|
+
return new EVMBtcStoredHeader({
|
|
114
|
+
blockheader,
|
|
115
|
+
blockHash: blockheader.getHash(),
|
|
116
|
+
chainWork: base_1.BigIntBufferUtils.fromBuffer(data.subarray(80, 112)),
|
|
117
|
+
blockHeight: data.readUint32BE(112),
|
|
118
|
+
lastDiffAdjustment: data.readUint32BE(116),
|
|
119
|
+
prevBlockTimestamps
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.EVMBtcStoredHeader = EVMBtcStoredHeader;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ChainInterface, TransactionConfirmationOptions } from "@atomiqlabs/base";
|
|
2
|
+
import { LoggerType } from "../../utils/Utils";
|
|
3
|
+
import { JsonRpcApiProvider, Transaction, TransactionRequest } from "ethers";
|
|
4
|
+
import { EVMBlocks, EVMBlockTag } from "./modules/EVMBlocks";
|
|
5
|
+
import { EVMEvents } from "./modules/EVMEvents";
|
|
6
|
+
import { EVMFees } from "./modules/EVMFees";
|
|
7
|
+
import { EVMTokens } from "./modules/EVMTokens";
|
|
8
|
+
import { EVMTransactions } from "./modules/EVMTransactions";
|
|
9
|
+
import { EVMSignatures } from "./modules/EVMSignatures";
|
|
10
|
+
import { EVMSigner } from "../wallet/EVMSigner";
|
|
11
|
+
export type EVMRetryPolicy = {
|
|
12
|
+
maxRetries?: number;
|
|
13
|
+
delay?: number;
|
|
14
|
+
exponential?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type EVMConfiguration = {
|
|
17
|
+
safeBlockTag: EVMBlockTag;
|
|
18
|
+
maxLogsBlockRange: number;
|
|
19
|
+
};
|
|
20
|
+
export declare class EVMChainInterface<ChainId extends string = string, EVMChainId extends number = number> implements ChainInterface {
|
|
21
|
+
readonly chainId: ChainId;
|
|
22
|
+
readonly provider: JsonRpcApiProvider;
|
|
23
|
+
readonly retryPolicy: EVMRetryPolicy;
|
|
24
|
+
readonly evmChainId: EVMChainId;
|
|
25
|
+
readonly config: EVMConfiguration;
|
|
26
|
+
Fees: EVMFees;
|
|
27
|
+
readonly Tokens: EVMTokens;
|
|
28
|
+
readonly Transactions: EVMTransactions;
|
|
29
|
+
readonly Signatures: EVMSignatures;
|
|
30
|
+
readonly Events: EVMEvents;
|
|
31
|
+
readonly Blocks: EVMBlocks;
|
|
32
|
+
protected readonly logger: LoggerType;
|
|
33
|
+
constructor(chainId: ChainId, evmChainId: EVMChainId, provider: JsonRpcApiProvider, config: EVMConfiguration, retryPolicy?: EVMRetryPolicy, evmFeeEstimator?: EVMFees);
|
|
34
|
+
getBalance(signer: string, tokenAddress: string): Promise<bigint>;
|
|
35
|
+
getNativeCurrencyAddress(): string;
|
|
36
|
+
isValidToken(tokenIdentifier: string): boolean;
|
|
37
|
+
isValidAddress(address: string): boolean;
|
|
38
|
+
offBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): boolean;
|
|
39
|
+
onBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): void;
|
|
40
|
+
onBeforeTxSigned(callback: (tx: TransactionRequest) => Promise<void>): void;
|
|
41
|
+
offBeforeTxSigned(callback: (tx: TransactionRequest) => Promise<void>): boolean;
|
|
42
|
+
randomAddress(): string;
|
|
43
|
+
randomSigner(): EVMSigner;
|
|
44
|
+
sendAndConfirm(signer: EVMSigner, txs: TransactionRequest[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
|
|
45
|
+
serializeTx(tx: Transaction): Promise<string>;
|
|
46
|
+
deserializeTx(txData: string): Promise<Transaction>;
|
|
47
|
+
getTxIdStatus(txId: string): Promise<"not_found" | "pending" | "success" | "reverted">;
|
|
48
|
+
getTxStatus(tx: string): Promise<"not_found" | "pending" | "success" | "reverted">;
|
|
49
|
+
txsTransfer(signer: string, token: string, amount: bigint, dstAddress: string, feeRate?: string): Promise<TransactionRequest[]>;
|
|
50
|
+
transfer(signer: EVMSigner, token: string, amount: bigint, dstAddress: string, txOptions?: TransactionConfirmationOptions): Promise<string>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EVMChainInterface = void 0;
|
|
4
|
+
const Utils_1 = require("../../utils/Utils");
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
const EVMBlocks_1 = require("./modules/EVMBlocks");
|
|
7
|
+
const EVMEvents_1 = require("./modules/EVMEvents");
|
|
8
|
+
const EVMFees_1 = require("./modules/EVMFees");
|
|
9
|
+
const EVMTokens_1 = require("./modules/EVMTokens");
|
|
10
|
+
const EVMTransactions_1 = require("./modules/EVMTransactions");
|
|
11
|
+
const EVMSignatures_1 = require("./modules/EVMSignatures");
|
|
12
|
+
const EVMAddresses_1 = require("./modules/EVMAddresses");
|
|
13
|
+
const EVMSigner_1 = require("../wallet/EVMSigner");
|
|
14
|
+
class EVMChainInterface {
|
|
15
|
+
constructor(chainId, evmChainId, provider, config, retryPolicy, evmFeeEstimator = new EVMFees_1.EVMFees(provider)) {
|
|
16
|
+
var _a;
|
|
17
|
+
this.chainId = chainId;
|
|
18
|
+
this.evmChainId = evmChainId;
|
|
19
|
+
this.provider = provider;
|
|
20
|
+
this.retryPolicy = retryPolicy;
|
|
21
|
+
this.config = config;
|
|
22
|
+
(_a = this.config).safeBlockTag ?? (_a.safeBlockTag = "safe");
|
|
23
|
+
this.logger = (0, Utils_1.getLogger)("EVMChainInterface(" + this.evmChainId + "): ");
|
|
24
|
+
this.Fees = evmFeeEstimator;
|
|
25
|
+
this.Tokens = new EVMTokens_1.EVMTokens(this);
|
|
26
|
+
this.Transactions = new EVMTransactions_1.EVMTransactions(this);
|
|
27
|
+
this.Signatures = new EVMSignatures_1.EVMSignatures(this);
|
|
28
|
+
this.Events = new EVMEvents_1.EVMEvents(this);
|
|
29
|
+
this.Blocks = new EVMBlocks_1.EVMBlocks(this);
|
|
30
|
+
}
|
|
31
|
+
async getBalance(signer, tokenAddress) {
|
|
32
|
+
//TODO: For native token we should discount the cost of transactions
|
|
33
|
+
return await this.Tokens.getTokenBalance(signer, tokenAddress);
|
|
34
|
+
}
|
|
35
|
+
getNativeCurrencyAddress() {
|
|
36
|
+
return this.Tokens.getNativeCurrencyAddress();
|
|
37
|
+
}
|
|
38
|
+
isValidToken(tokenIdentifier) {
|
|
39
|
+
return this.Tokens.isValidToken(tokenIdentifier);
|
|
40
|
+
}
|
|
41
|
+
isValidAddress(address) {
|
|
42
|
+
return EVMAddresses_1.EVMAddresses.isValidAddress(address);
|
|
43
|
+
}
|
|
44
|
+
///////////////////////////////////
|
|
45
|
+
//// Callbacks & handlers
|
|
46
|
+
offBeforeTxReplace(callback) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
onBeforeTxReplace(callback) { }
|
|
50
|
+
onBeforeTxSigned(callback) {
|
|
51
|
+
this.Transactions.onBeforeTxSigned(callback);
|
|
52
|
+
}
|
|
53
|
+
offBeforeTxSigned(callback) {
|
|
54
|
+
return this.Transactions.offBeforeTxSigned(callback);
|
|
55
|
+
}
|
|
56
|
+
randomAddress() {
|
|
57
|
+
const wallet = ethers_1.Wallet.createRandom();
|
|
58
|
+
return wallet.address;
|
|
59
|
+
}
|
|
60
|
+
randomSigner() {
|
|
61
|
+
const wallet = ethers_1.Wallet.createRandom();
|
|
62
|
+
return new EVMSigner_1.EVMSigner(wallet, wallet.address);
|
|
63
|
+
}
|
|
64
|
+
////////////////////////////////////////////
|
|
65
|
+
//// Transactions
|
|
66
|
+
sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
|
|
67
|
+
return this.Transactions.sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
|
|
68
|
+
}
|
|
69
|
+
serializeTx(tx) {
|
|
70
|
+
return this.Transactions.serializeTx(tx);
|
|
71
|
+
}
|
|
72
|
+
deserializeTx(txData) {
|
|
73
|
+
return this.Transactions.deserializeTx(txData);
|
|
74
|
+
}
|
|
75
|
+
getTxIdStatus(txId) {
|
|
76
|
+
return this.Transactions.getTxIdStatus(txId);
|
|
77
|
+
}
|
|
78
|
+
getTxStatus(tx) {
|
|
79
|
+
return this.Transactions.getTxStatus(tx);
|
|
80
|
+
}
|
|
81
|
+
async txsTransfer(signer, token, amount, dstAddress, feeRate) {
|
|
82
|
+
return [await this.Tokens.Transfer(signer, token, amount, dstAddress, feeRate)];
|
|
83
|
+
}
|
|
84
|
+
async transfer(signer, token, amount, dstAddress, txOptions) {
|
|
85
|
+
const tx = await this.Tokens.Transfer(signer.getAddress(), token, amount, dstAddress, txOptions?.feeRate);
|
|
86
|
+
const [txId] = await this.Transactions.sendAndConfirm(signer, [tx], txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
|
|
87
|
+
return txId;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.EVMChainInterface = EVMChainInterface;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { JsonRpcApiProvider } from "ethers";
|
|
2
|
+
import { EVMChainInterface, EVMRetryPolicy } from "./EVMChainInterface";
|
|
3
|
+
export declare class EVMModule<ChainId extends string = string, EVMChainId extends number = number> {
|
|
4
|
+
protected readonly provider: JsonRpcApiProvider;
|
|
5
|
+
protected readonly retryPolicy: EVMRetryPolicy;
|
|
6
|
+
protected readonly root: EVMChainInterface<ChainId, EVMChainId>;
|
|
7
|
+
protected readonly logger: import("../../utils/Utils").LoggerType;
|
|
8
|
+
constructor(root: EVMChainInterface<ChainId, EVMChainId>);
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EVMModule = void 0;
|
|
4
|
+
const Utils_1 = require("../../utils/Utils");
|
|
5
|
+
class EVMModule {
|
|
6
|
+
constructor(root) {
|
|
7
|
+
this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
|
|
8
|
+
this.provider = root.provider;
|
|
9
|
+
this.retryPolicy = root.retryPolicy;
|
|
10
|
+
this.root = root;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.EVMModule = EVMModule;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
export declare const ERC20Abi: readonly [{
|
|
2
|
+
readonly constant: true;
|
|
3
|
+
readonly inputs: readonly [];
|
|
4
|
+
readonly name: "name";
|
|
5
|
+
readonly outputs: readonly [{
|
|
6
|
+
readonly name: "";
|
|
7
|
+
readonly type: "string";
|
|
8
|
+
}];
|
|
9
|
+
readonly payable: false;
|
|
10
|
+
readonly stateMutability: "view";
|
|
11
|
+
readonly type: "function";
|
|
12
|
+
}, {
|
|
13
|
+
readonly constant: false;
|
|
14
|
+
readonly inputs: readonly [{
|
|
15
|
+
readonly name: "_spender";
|
|
16
|
+
readonly type: "address";
|
|
17
|
+
}, {
|
|
18
|
+
readonly name: "_value";
|
|
19
|
+
readonly type: "uint256";
|
|
20
|
+
}];
|
|
21
|
+
readonly name: "approve";
|
|
22
|
+
readonly outputs: readonly [{
|
|
23
|
+
readonly name: "";
|
|
24
|
+
readonly type: "bool";
|
|
25
|
+
}];
|
|
26
|
+
readonly payable: false;
|
|
27
|
+
readonly stateMutability: "nonpayable";
|
|
28
|
+
readonly type: "function";
|
|
29
|
+
}, {
|
|
30
|
+
readonly constant: true;
|
|
31
|
+
readonly inputs: readonly [];
|
|
32
|
+
readonly name: "totalSupply";
|
|
33
|
+
readonly outputs: readonly [{
|
|
34
|
+
readonly name: "";
|
|
35
|
+
readonly type: "uint256";
|
|
36
|
+
}];
|
|
37
|
+
readonly payable: false;
|
|
38
|
+
readonly stateMutability: "view";
|
|
39
|
+
readonly type: "function";
|
|
40
|
+
}, {
|
|
41
|
+
readonly constant: false;
|
|
42
|
+
readonly inputs: readonly [{
|
|
43
|
+
readonly name: "_from";
|
|
44
|
+
readonly type: "address";
|
|
45
|
+
}, {
|
|
46
|
+
readonly name: "_to";
|
|
47
|
+
readonly type: "address";
|
|
48
|
+
}, {
|
|
49
|
+
readonly name: "_value";
|
|
50
|
+
readonly type: "uint256";
|
|
51
|
+
}];
|
|
52
|
+
readonly name: "transferFrom";
|
|
53
|
+
readonly outputs: readonly [{
|
|
54
|
+
readonly name: "";
|
|
55
|
+
readonly type: "bool";
|
|
56
|
+
}];
|
|
57
|
+
readonly payable: false;
|
|
58
|
+
readonly stateMutability: "nonpayable";
|
|
59
|
+
readonly type: "function";
|
|
60
|
+
}, {
|
|
61
|
+
readonly constant: true;
|
|
62
|
+
readonly inputs: readonly [];
|
|
63
|
+
readonly name: "decimals";
|
|
64
|
+
readonly outputs: readonly [{
|
|
65
|
+
readonly name: "";
|
|
66
|
+
readonly type: "uint8";
|
|
67
|
+
}];
|
|
68
|
+
readonly payable: false;
|
|
69
|
+
readonly stateMutability: "view";
|
|
70
|
+
readonly type: "function";
|
|
71
|
+
}, {
|
|
72
|
+
readonly constant: true;
|
|
73
|
+
readonly inputs: readonly [{
|
|
74
|
+
readonly name: "_owner";
|
|
75
|
+
readonly type: "address";
|
|
76
|
+
}];
|
|
77
|
+
readonly name: "balanceOf";
|
|
78
|
+
readonly outputs: readonly [{
|
|
79
|
+
readonly name: "balance";
|
|
80
|
+
readonly type: "uint256";
|
|
81
|
+
}];
|
|
82
|
+
readonly payable: false;
|
|
83
|
+
readonly stateMutability: "view";
|
|
84
|
+
readonly type: "function";
|
|
85
|
+
}, {
|
|
86
|
+
readonly constant: true;
|
|
87
|
+
readonly inputs: readonly [];
|
|
88
|
+
readonly name: "symbol";
|
|
89
|
+
readonly outputs: readonly [{
|
|
90
|
+
readonly name: "";
|
|
91
|
+
readonly type: "string";
|
|
92
|
+
}];
|
|
93
|
+
readonly payable: false;
|
|
94
|
+
readonly stateMutability: "view";
|
|
95
|
+
readonly type: "function";
|
|
96
|
+
}, {
|
|
97
|
+
readonly constant: false;
|
|
98
|
+
readonly inputs: readonly [{
|
|
99
|
+
readonly name: "_to";
|
|
100
|
+
readonly type: "address";
|
|
101
|
+
}, {
|
|
102
|
+
readonly name: "_value";
|
|
103
|
+
readonly type: "uint256";
|
|
104
|
+
}];
|
|
105
|
+
readonly name: "transfer";
|
|
106
|
+
readonly outputs: readonly [{
|
|
107
|
+
readonly name: "";
|
|
108
|
+
readonly type: "bool";
|
|
109
|
+
}];
|
|
110
|
+
readonly payable: false;
|
|
111
|
+
readonly stateMutability: "nonpayable";
|
|
112
|
+
readonly type: "function";
|
|
113
|
+
}, {
|
|
114
|
+
readonly constant: true;
|
|
115
|
+
readonly inputs: readonly [{
|
|
116
|
+
readonly name: "_owner";
|
|
117
|
+
readonly type: "address";
|
|
118
|
+
}, {
|
|
119
|
+
readonly name: "_spender";
|
|
120
|
+
readonly type: "address";
|
|
121
|
+
}];
|
|
122
|
+
readonly name: "allowance";
|
|
123
|
+
readonly outputs: readonly [{
|
|
124
|
+
readonly name: "";
|
|
125
|
+
readonly type: "uint256";
|
|
126
|
+
}];
|
|
127
|
+
readonly payable: false;
|
|
128
|
+
readonly stateMutability: "view";
|
|
129
|
+
readonly type: "function";
|
|
130
|
+
}, {
|
|
131
|
+
readonly payable: true;
|
|
132
|
+
readonly stateMutability: "payable";
|
|
133
|
+
readonly type: "fallback";
|
|
134
|
+
}, {
|
|
135
|
+
readonly anonymous: false;
|
|
136
|
+
readonly inputs: readonly [{
|
|
137
|
+
readonly indexed: true;
|
|
138
|
+
readonly name: "owner";
|
|
139
|
+
readonly type: "address";
|
|
140
|
+
}, {
|
|
141
|
+
readonly indexed: true;
|
|
142
|
+
readonly name: "spender";
|
|
143
|
+
readonly type: "address";
|
|
144
|
+
}, {
|
|
145
|
+
readonly indexed: false;
|
|
146
|
+
readonly name: "value";
|
|
147
|
+
readonly type: "uint256";
|
|
148
|
+
}];
|
|
149
|
+
readonly name: "Approval";
|
|
150
|
+
readonly type: "event";
|
|
151
|
+
}, {
|
|
152
|
+
readonly anonymous: false;
|
|
153
|
+
readonly inputs: readonly [{
|
|
154
|
+
readonly indexed: true;
|
|
155
|
+
readonly name: "from";
|
|
156
|
+
readonly type: "address";
|
|
157
|
+
}, {
|
|
158
|
+
readonly indexed: true;
|
|
159
|
+
readonly name: "to";
|
|
160
|
+
readonly type: "address";
|
|
161
|
+
}, {
|
|
162
|
+
readonly indexed: false;
|
|
163
|
+
readonly name: "value";
|
|
164
|
+
readonly type: "uint256";
|
|
165
|
+
}];
|
|
166
|
+
readonly name: "Transfer";
|
|
167
|
+
readonly type: "event";
|
|
168
|
+
}];
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERC20Abi = void 0;
|
|
4
|
+
exports.ERC20Abi = [
|
|
5
|
+
{
|
|
6
|
+
"constant": true,
|
|
7
|
+
"inputs": [],
|
|
8
|
+
"name": "name",
|
|
9
|
+
"outputs": [
|
|
10
|
+
{
|
|
11
|
+
"name": "",
|
|
12
|
+
"type": "string"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"payable": false,
|
|
16
|
+
"stateMutability": "view",
|
|
17
|
+
"type": "function"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"constant": false,
|
|
21
|
+
"inputs": [
|
|
22
|
+
{
|
|
23
|
+
"name": "_spender",
|
|
24
|
+
"type": "address"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "_value",
|
|
28
|
+
"type": "uint256"
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"name": "approve",
|
|
32
|
+
"outputs": [
|
|
33
|
+
{
|
|
34
|
+
"name": "",
|
|
35
|
+
"type": "bool"
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"payable": false,
|
|
39
|
+
"stateMutability": "nonpayable",
|
|
40
|
+
"type": "function"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"constant": true,
|
|
44
|
+
"inputs": [],
|
|
45
|
+
"name": "totalSupply",
|
|
46
|
+
"outputs": [
|
|
47
|
+
{
|
|
48
|
+
"name": "",
|
|
49
|
+
"type": "uint256"
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
"payable": false,
|
|
53
|
+
"stateMutability": "view",
|
|
54
|
+
"type": "function"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"constant": false,
|
|
58
|
+
"inputs": [
|
|
59
|
+
{
|
|
60
|
+
"name": "_from",
|
|
61
|
+
"type": "address"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"name": "_to",
|
|
65
|
+
"type": "address"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"name": "_value",
|
|
69
|
+
"type": "uint256"
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
"name": "transferFrom",
|
|
73
|
+
"outputs": [
|
|
74
|
+
{
|
|
75
|
+
"name": "",
|
|
76
|
+
"type": "bool"
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
"payable": false,
|
|
80
|
+
"stateMutability": "nonpayable",
|
|
81
|
+
"type": "function"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"constant": true,
|
|
85
|
+
"inputs": [],
|
|
86
|
+
"name": "decimals",
|
|
87
|
+
"outputs": [
|
|
88
|
+
{
|
|
89
|
+
"name": "",
|
|
90
|
+
"type": "uint8"
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
"payable": false,
|
|
94
|
+
"stateMutability": "view",
|
|
95
|
+
"type": "function"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"constant": true,
|
|
99
|
+
"inputs": [
|
|
100
|
+
{
|
|
101
|
+
"name": "_owner",
|
|
102
|
+
"type": "address"
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
"name": "balanceOf",
|
|
106
|
+
"outputs": [
|
|
107
|
+
{
|
|
108
|
+
"name": "balance",
|
|
109
|
+
"type": "uint256"
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
"payable": false,
|
|
113
|
+
"stateMutability": "view",
|
|
114
|
+
"type": "function"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"constant": true,
|
|
118
|
+
"inputs": [],
|
|
119
|
+
"name": "symbol",
|
|
120
|
+
"outputs": [
|
|
121
|
+
{
|
|
122
|
+
"name": "",
|
|
123
|
+
"type": "string"
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
"payable": false,
|
|
127
|
+
"stateMutability": "view",
|
|
128
|
+
"type": "function"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"constant": false,
|
|
132
|
+
"inputs": [
|
|
133
|
+
{
|
|
134
|
+
"name": "_to",
|
|
135
|
+
"type": "address"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"name": "_value",
|
|
139
|
+
"type": "uint256"
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
"name": "transfer",
|
|
143
|
+
"outputs": [
|
|
144
|
+
{
|
|
145
|
+
"name": "",
|
|
146
|
+
"type": "bool"
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
"payable": false,
|
|
150
|
+
"stateMutability": "nonpayable",
|
|
151
|
+
"type": "function"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"constant": true,
|
|
155
|
+
"inputs": [
|
|
156
|
+
{
|
|
157
|
+
"name": "_owner",
|
|
158
|
+
"type": "address"
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"name": "_spender",
|
|
162
|
+
"type": "address"
|
|
163
|
+
}
|
|
164
|
+
],
|
|
165
|
+
"name": "allowance",
|
|
166
|
+
"outputs": [
|
|
167
|
+
{
|
|
168
|
+
"name": "",
|
|
169
|
+
"type": "uint256"
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
"payable": false,
|
|
173
|
+
"stateMutability": "view",
|
|
174
|
+
"type": "function"
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"payable": true,
|
|
178
|
+
"stateMutability": "payable",
|
|
179
|
+
"type": "fallback"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"anonymous": false,
|
|
183
|
+
"inputs": [
|
|
184
|
+
{
|
|
185
|
+
"indexed": true,
|
|
186
|
+
"name": "owner",
|
|
187
|
+
"type": "address"
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"indexed": true,
|
|
191
|
+
"name": "spender",
|
|
192
|
+
"type": "address"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"indexed": false,
|
|
196
|
+
"name": "value",
|
|
197
|
+
"type": "uint256"
|
|
198
|
+
}
|
|
199
|
+
],
|
|
200
|
+
"name": "Approval",
|
|
201
|
+
"type": "event"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"anonymous": false,
|
|
205
|
+
"inputs": [
|
|
206
|
+
{
|
|
207
|
+
"indexed": true,
|
|
208
|
+
"name": "from",
|
|
209
|
+
"type": "address"
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"indexed": true,
|
|
213
|
+
"name": "to",
|
|
214
|
+
"type": "address"
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"indexed": false,
|
|
218
|
+
"name": "value",
|
|
219
|
+
"type": "uint256"
|
|
220
|
+
}
|
|
221
|
+
],
|
|
222
|
+
"name": "Transfer",
|
|
223
|
+
"type": "event"
|
|
224
|
+
}
|
|
225
|
+
];
|