@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,201 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SpvVaultClaimEvent,
|
|
3
|
+
SpvVaultCloseEvent,
|
|
4
|
+
SpvVaultData, SpvVaultDepositEvent, SpvVaultOpenEvent,
|
|
5
|
+
SpvVaultTokenBalance,
|
|
6
|
+
SpvVaultTokenData
|
|
7
|
+
} from "@atomiqlabs/base";
|
|
8
|
+
import {Buffer} from "buffer";
|
|
9
|
+
import { EVMSpvWithdrawalData } from "./EVMSpvWithdrawalData";
|
|
10
|
+
import {
|
|
11
|
+
SpvVaultParametersStruct,
|
|
12
|
+
SpvVaultStateStruct
|
|
13
|
+
} from "./SpvVaultContractTypechain";
|
|
14
|
+
import {hexlify} from "ethers";
|
|
15
|
+
import {AbiCoder, keccak256} from "ethers";
|
|
16
|
+
|
|
17
|
+
export function getVaultParamsCommitment(vaultParams: SpvVaultParametersStruct) {
|
|
18
|
+
return keccak256(AbiCoder.defaultAbiCoder().encode(
|
|
19
|
+
["address", "address", "address", "uint192", "uint192", "uint256"],
|
|
20
|
+
[vaultParams.btcRelayContract, vaultParams.token0, vaultParams.token1, vaultParams.token0Multiplier, vaultParams.token1Multiplier, vaultParams.confirmations]
|
|
21
|
+
));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class EVMSpvVaultData extends SpvVaultData<EVMSpvWithdrawalData> {
|
|
25
|
+
|
|
26
|
+
readonly owner: string;
|
|
27
|
+
readonly vaultId: bigint;
|
|
28
|
+
|
|
29
|
+
readonly relayContract: string;
|
|
30
|
+
readonly token0: {
|
|
31
|
+
token: string,
|
|
32
|
+
multiplier: bigint,
|
|
33
|
+
rawAmount: bigint
|
|
34
|
+
}
|
|
35
|
+
readonly token1: {
|
|
36
|
+
token: string,
|
|
37
|
+
multiplier: bigint,
|
|
38
|
+
rawAmount: bigint
|
|
39
|
+
};
|
|
40
|
+
readonly initialUtxo: string;
|
|
41
|
+
utxo: string;
|
|
42
|
+
readonly confirmations: number;
|
|
43
|
+
withdrawCount: number;
|
|
44
|
+
depositCount: number;
|
|
45
|
+
|
|
46
|
+
constructor(owner: string, vaultId: bigint, state: SpvVaultStateStruct, params: SpvVaultParametersStruct, initialUtxo?: string);
|
|
47
|
+
constructor(serializedObj: any);
|
|
48
|
+
constructor(ownerOrObj: string | any, vaultId?: bigint, state?: SpvVaultStateStruct, params?: SpvVaultParametersStruct, initialUtxo?: string) {
|
|
49
|
+
super();
|
|
50
|
+
if(typeof(ownerOrObj) === "string") {
|
|
51
|
+
this.owner = ownerOrObj;
|
|
52
|
+
this.vaultId = vaultId;
|
|
53
|
+
this.relayContract = params.btcRelayContract as string;
|
|
54
|
+
this.token0 = {
|
|
55
|
+
token: params.token0 as string,
|
|
56
|
+
multiplier: BigInt(params.token0Multiplier),
|
|
57
|
+
rawAmount: BigInt(state.token0Amount)
|
|
58
|
+
};
|
|
59
|
+
this.token1 = {
|
|
60
|
+
token: params.token1 as string,
|
|
61
|
+
multiplier: BigInt(params.token1Multiplier),
|
|
62
|
+
rawAmount: BigInt(state.token1Amount)
|
|
63
|
+
};
|
|
64
|
+
const txHash = Buffer.from(hexlify(state.utxoTxHash).substring(2), "hex");
|
|
65
|
+
this.utxo = txHash.reverse().toString("hex")+":"+BigInt(state.utxoVout).toString(10);
|
|
66
|
+
this.confirmations = Number(params.confirmations);
|
|
67
|
+
this.withdrawCount = Number(state.withdrawCount);
|
|
68
|
+
this.depositCount = Number(state.depositCount);
|
|
69
|
+
this.initialUtxo = initialUtxo;
|
|
70
|
+
} else {
|
|
71
|
+
this.owner = ownerOrObj.owner;
|
|
72
|
+
this.vaultId = BigInt(ownerOrObj.vaultId);
|
|
73
|
+
this.relayContract = ownerOrObj.relayContract;
|
|
74
|
+
this.token0 = {
|
|
75
|
+
token: ownerOrObj.token0.token,
|
|
76
|
+
multiplier: BigInt(ownerOrObj.token0.multiplier),
|
|
77
|
+
rawAmount: BigInt(ownerOrObj.token0.rawAmount)
|
|
78
|
+
}
|
|
79
|
+
this.token1 = {
|
|
80
|
+
token: ownerOrObj.token1.token,
|
|
81
|
+
multiplier: BigInt(ownerOrObj.token1.multiplier),
|
|
82
|
+
rawAmount: BigInt(ownerOrObj.token1.rawAmount)
|
|
83
|
+
};
|
|
84
|
+
this.utxo = ownerOrObj.utxo;
|
|
85
|
+
this.confirmations = ownerOrObj.confirmations;
|
|
86
|
+
this.withdrawCount = ownerOrObj.withdrawCount;
|
|
87
|
+
this.depositCount = ownerOrObj.depositCount;
|
|
88
|
+
this.initialUtxo = ownerOrObj.initialUtxo;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getBalances(): SpvVaultTokenBalance[] {
|
|
93
|
+
return [
|
|
94
|
+
{...this.token0, scaledAmount: this.token0.rawAmount * this.token0.multiplier},
|
|
95
|
+
{...this.token1, scaledAmount: this.token1.rawAmount * this.token1.multiplier}
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
getConfirmations(): number {
|
|
100
|
+
return this.confirmations;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getOwner(): string {
|
|
104
|
+
return this.owner;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
getTokenData(): SpvVaultTokenData[] {
|
|
108
|
+
return [this.token0, this.token1];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getUtxo(): string {
|
|
112
|
+
return this.isOpened() ? this.utxo : this.initialUtxo;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getVaultId(): bigint {
|
|
116
|
+
return this.vaultId;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getWithdrawalCount(): number {
|
|
120
|
+
return this.withdrawCount;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
isOpened(): boolean {
|
|
124
|
+
return this.utxo!=="0000000000000000000000000000000000000000000000000000000000000000:0";
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
serialize(): any {
|
|
128
|
+
return {
|
|
129
|
+
type: "EVM",
|
|
130
|
+
owner: this.owner,
|
|
131
|
+
vaultId: this.vaultId.toString(10),
|
|
132
|
+
relayContract: this.relayContract,
|
|
133
|
+
token0: {
|
|
134
|
+
token: this.token0.token,
|
|
135
|
+
multiplier: this.token0.multiplier.toString(10),
|
|
136
|
+
rawAmount: this.token0.rawAmount.toString(10)
|
|
137
|
+
},
|
|
138
|
+
token1: {
|
|
139
|
+
token: this.token1.token,
|
|
140
|
+
multiplier: this.token1.multiplier.toString(10),
|
|
141
|
+
rawAmount: this.token1.rawAmount.toString(10)
|
|
142
|
+
},
|
|
143
|
+
utxo: this.utxo,
|
|
144
|
+
confirmations: this.confirmations,
|
|
145
|
+
withdrawCount: this.withdrawCount,
|
|
146
|
+
depositCount: this.depositCount,
|
|
147
|
+
initialUtxo: this.initialUtxo
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
updateState(withdrawalTxOrEvent: SpvVaultClaimEvent | SpvVaultCloseEvent | SpvVaultOpenEvent | SpvVaultDepositEvent | EVMSpvWithdrawalData): void {
|
|
152
|
+
if(withdrawalTxOrEvent instanceof SpvVaultClaimEvent) {
|
|
153
|
+
if(withdrawalTxOrEvent.withdrawCount <= this.withdrawCount) return;
|
|
154
|
+
this.token0.rawAmount -= withdrawalTxOrEvent.amounts[0];
|
|
155
|
+
this.token1.rawAmount -= withdrawalTxOrEvent.amounts[1];
|
|
156
|
+
this.withdrawCount = withdrawalTxOrEvent.withdrawCount;
|
|
157
|
+
this.utxo = withdrawalTxOrEvent.btcTxId+":0";
|
|
158
|
+
}
|
|
159
|
+
if(withdrawalTxOrEvent instanceof SpvVaultCloseEvent) {
|
|
160
|
+
this.token0.rawAmount = 0n;
|
|
161
|
+
this.token1.rawAmount = 0n;
|
|
162
|
+
this.utxo = "0000000000000000000000000000000000000000000000000000000000000000:0";
|
|
163
|
+
}
|
|
164
|
+
if(withdrawalTxOrEvent instanceof SpvVaultOpenEvent) {
|
|
165
|
+
if(this.isOpened()) return;
|
|
166
|
+
this.utxo = withdrawalTxOrEvent.btcTxId+":"+withdrawalTxOrEvent.vout;
|
|
167
|
+
}
|
|
168
|
+
if(withdrawalTxOrEvent instanceof SpvVaultDepositEvent) {
|
|
169
|
+
if(withdrawalTxOrEvent.depositCount <= this.depositCount) return;
|
|
170
|
+
this.token0.rawAmount += withdrawalTxOrEvent.amounts[0];
|
|
171
|
+
this.token1.rawAmount += withdrawalTxOrEvent.amounts[1];
|
|
172
|
+
this.depositCount = withdrawalTxOrEvent.depositCount;
|
|
173
|
+
}
|
|
174
|
+
if(withdrawalTxOrEvent instanceof EVMSpvWithdrawalData) {
|
|
175
|
+
if(withdrawalTxOrEvent.getSpentVaultUtxo()!==this.utxo) return;
|
|
176
|
+
const amounts = withdrawalTxOrEvent.getTotalOutput();
|
|
177
|
+
this.token0.rawAmount -= amounts[0];
|
|
178
|
+
this.token1.rawAmount -= amounts[1];
|
|
179
|
+
this.withdrawCount++;
|
|
180
|
+
this.utxo = withdrawalTxOrEvent.btcTx.txid+":0";
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
getDepositCount(): number {
|
|
185
|
+
return this.depositCount;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
getVaultParamsStruct(): SpvVaultParametersStruct {
|
|
189
|
+
return {
|
|
190
|
+
btcRelayContract: this.relayContract,
|
|
191
|
+
token0: this.token0.token,
|
|
192
|
+
token1: this.token1.token,
|
|
193
|
+
token0Multiplier: this.token0.multiplier,
|
|
194
|
+
token1Multiplier: this.token1.multiplier,
|
|
195
|
+
confirmations: this.confirmations
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
SpvVaultData.deserializers["EVM"] = EVMSpvVaultData;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {SpvWithdrawalTransactionData} from "@atomiqlabs/base";
|
|
2
|
+
import {Buffer} from "buffer";
|
|
3
|
+
import { EVMSpvVaultContract } from "./EVMSpvVaultContract";
|
|
4
|
+
import {BitcoinVaultTransactionDataStruct} from "./SpvVaultContractTypechain";
|
|
5
|
+
import {AbiCoder, keccak256, ZeroHash} from "ethers";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export class EVMSpvWithdrawalData extends SpvWithdrawalTransactionData {
|
|
9
|
+
|
|
10
|
+
private getExecutionHashWith0x() {
|
|
11
|
+
return this.executionHash==null ? ZeroHash : (this.executionHash.startsWith("0x") ? this.executionHash : "0x"+this.executionHash)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
protected fromOpReturnData(data: Buffer): { recipient: string; rawAmounts: bigint[]; executionHash: string } {
|
|
15
|
+
return EVMSpvVaultContract.fromOpReturnData(data);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
isRecipient(address: string): boolean {
|
|
19
|
+
return this.getRecipient().toLowerCase()===address.toLowerCase();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getFrontingId(): string {
|
|
23
|
+
const callerFee = this.getCallerFee();
|
|
24
|
+
const frontingFee = this.getFrontingFee();
|
|
25
|
+
const txDataHash = keccak256(AbiCoder.defaultAbiCoder().encode(
|
|
26
|
+
["address", "uint64", "uint64", "uint64", "uint64", "uint64", "uint64", "uint64", "bytes32", "uint256"],
|
|
27
|
+
[this.recipient, this.rawAmounts[0], this.rawAmounts[1], callerFee[0], callerFee[1], frontingFee[0], frontingFee[1], this.getExecutionFee()[0], this.getExecutionHashWith0x(), this.executionExpiry]
|
|
28
|
+
));
|
|
29
|
+
return keccak256(AbiCoder.defaultAbiCoder().encode(
|
|
30
|
+
["bytes32", "bytes32"],
|
|
31
|
+
[txDataHash, this.getTxHash()]
|
|
32
|
+
)).substring(2);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getTxHash(): string {
|
|
36
|
+
return "0x"+Buffer.from(this.btcTx.txid, "hex").reverse().toString("hex");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getFrontingAmount(): bigint[] {
|
|
40
|
+
return [this.rawAmounts[0] + this.getExecutionFee()[0], this.rawAmounts[1]];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
serialize(): any {
|
|
44
|
+
return {
|
|
45
|
+
type: "EVM",
|
|
46
|
+
...super.serialize()
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
serializeToStruct(): BitcoinVaultTransactionDataStruct {
|
|
51
|
+
const callerFee = this.getCallerFee();
|
|
52
|
+
const frontingFee = this.getFrontingFee();
|
|
53
|
+
const executionFee = this.getExecutionFee();
|
|
54
|
+
return {
|
|
55
|
+
recipient: this.recipient,
|
|
56
|
+
amount0: this.rawAmounts[0],
|
|
57
|
+
amount1: this.rawAmounts[1] ?? 0n,
|
|
58
|
+
callerFee0: callerFee[0],
|
|
59
|
+
callerFee1: callerFee[1] ?? 0n,
|
|
60
|
+
frontingFee0: frontingFee[0],
|
|
61
|
+
frontingFee1: frontingFee[1] ?? 0n,
|
|
62
|
+
executionHandlerFeeAmount0: executionFee[0],
|
|
63
|
+
executionHash: this.getExecutionHashWith0x(),
|
|
64
|
+
executionExpiry: BigInt(this.executionExpiry)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
SpvWithdrawalTransactionData.deserializers["EVM"] = EVMSpvWithdrawalData;
|