Skip to content

Commit cb3378e

Browse files
authored
fix(satp): check gas usage on satp bridge manager (#3791)
Signed-off-by: Jorge Santos <[email protected]>
1 parent c029d2e commit cb3378e

File tree

12 files changed

+353
-48
lines changed

12 files changed

+353
-48
lines changed

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage0-client-service.ts

+4
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ export class Stage0ClientService extends SATPService {
426426
sessionData.senderWrapAssertionClaim.receipt =
427427
await bridge.wrapAsset(token);
428428

429+
this.Log.debug(
430+
`${fnTag}, Wrap Operation Receipt: ${sessionData.senderWrapAssertionClaim.receipt}`,
431+
);
432+
429433
sessionData.senderWrapAssertionClaim.proof =
430434
await bridge.getProof(assetId);
431435

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage2-client-service.ts

+5
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ export class Stage2ClientService extends SATPService {
278278
assetId,
279279
Number(amount),
280280
);
281+
282+
this.Log.debug(
283+
`${fnTag}, Lock Operation Receipt: ${sessionData.lockAssertionClaim.receipt}`,
284+
);
285+
281286
sessionData.lockAssertionClaim.proof = await bridge.getProof(assetId);
282287

283288
sessionData.lockAssertionClaimFormat = create(

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage3-client-service.ts

+5
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,11 @@ export class Stage3ClientService extends SATPService {
665665
assetId,
666666
Number(amount),
667667
);
668+
669+
this.Log.debug(
670+
`${fnTag}, Burn Operation Receipt: ${sessionData.burnAssertionClaim.receipt}`,
671+
);
672+
668673
sessionData.burnAssertionClaim.proof = await bridge.getProof(assetId);
669674

670675
sessionData.burnAssertionClaimFormat = create(

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage0-server-service.ts

+5
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,11 @@ export class Stage0ServerService extends SATPService {
569569
);
570570
sessionData.receiverWrapAssertionClaim.receipt =
571571
await bridge.wrapAsset(token);
572+
573+
this.Log.debug(
574+
`${fnTag}, Wrap Operation Receipt: ${sessionData.receiverWrapAssertionClaim.receipt}`,
575+
);
576+
572577
sessionData.receiverWrapAssertionClaim.proof =
573578
await bridge.getProof(assetId);
574579
sessionData.receiverWrapAssertionClaim.signature = bufArray2HexStr(

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/server/stage3-server-service.ts

+10
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,11 @@ export class Stage3ServerService extends SATPService {
692692
assetId,
693693
Number(amount),
694694
);
695+
696+
this.Log.debug(
697+
`${fnTag}, Mint Operation Receipt: ${sessionData.mintAssertionClaim.receipt}`,
698+
);
699+
695700
sessionData.mintAssertionClaim.proof = await bridge.getProof(assetId);
696701
sessionData.mintAssertionClaimFormat = create(
697702
MintAssertionClaimFormatSchema,
@@ -781,6 +786,11 @@ export class Stage3ServerService extends SATPService {
781786
recipient,
782787
Number(amount),
783788
);
789+
790+
this.Log.debug(
791+
`${fnTag}, Assign Operation Receipt: ${sessionData.assignmentAssertionClaim.receipt}`,
792+
);
793+
784794
sessionData.assignmentAssertionClaim.proof =
785795
await bridge.getProof(assetId);
786796
sessionData.assignmentAssertionClaimFormat = create(

packages/cactus-plugin-satp-hermes/src/main/typescript/cross-chain-mechanisms/satp-bridge/besu-bridge.ts

+34-11
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class BesuBridge implements NetworkBridge {
7272
}
7373

7474
public async wrapAsset(asset: EvmAsset): Promise<TransactionResponse> {
75-
const fnTag = `${BesuBridge.CLASS_NAME}}#wrapAsset`;
75+
const fnTag = `${BesuBridge.CLASS_NAME}#wrapAsset`;
7676
this.log.debug(
7777
`${fnTag}, Wrapping Asset: {${asset.tokenId}, ${asset.owner}, ${asset.contractAddress}, ${asset.tokenType}}`,
7878
);
@@ -110,7 +110,7 @@ export class BesuBridge implements NetworkBridge {
110110
};
111111
}
112112
public async unwrapAsset(assetId: string): Promise<TransactionResponse> {
113-
const fnTag = `${BesuBridge.CLASS_NAME}}#unwrapAsset`;
113+
const fnTag = `${BesuBridge.CLASS_NAME}#unwrapAsset`;
114114
this.log.debug(`${fnTag}, Unwrapping Asset: ${assetId}`);
115115
const response = (await this.connector.invokeContract({
116116
contractName: this.config.contractName,
@@ -134,7 +134,7 @@ export class BesuBridge implements NetworkBridge {
134134
assetId: string,
135135
amount: number,
136136
): Promise<TransactionResponse> {
137-
const fnTag = `${BesuBridge.CLASS_NAME}}#lockAsset`;
137+
const fnTag = `${BesuBridge.CLASS_NAME}#lockAsset`;
138138
this.log.debug(`${fnTag}, Locking Asset: ${assetId} amount: ${amount}`);
139139
const response = (await this.connector.invokeContract({
140140
contractName: this.config.contractName,
@@ -158,7 +158,7 @@ export class BesuBridge implements NetworkBridge {
158158
assetId: string,
159159
amount: number,
160160
): Promise<TransactionResponse> {
161-
const fnTag = `${BesuBridge.CLASS_NAME}}#unlockAsset`;
161+
const fnTag = `${BesuBridge.CLASS_NAME}#unlockAsset`;
162162
this.log.debug(`${fnTag}, Unlocking Asset: ${assetId} amount: ${amount}`);
163163
const response = (await this.connector.invokeContract({
164164
contractName: this.config.contractName,
@@ -182,7 +182,7 @@ export class BesuBridge implements NetworkBridge {
182182
assetId: string,
183183
amount: number,
184184
): Promise<TransactionResponse> {
185-
const fnTag = `${BesuBridge.CLASS_NAME}}#mintAsset`;
185+
const fnTag = `${BesuBridge.CLASS_NAME}#mintAsset`;
186186
this.log.debug(`${fnTag}, Minting Asset: ${assetId} amount: ${amount}`);
187187
const response = (await this.connector.invokeContract({
188188
contractName: this.config.contractName,
@@ -206,7 +206,7 @@ export class BesuBridge implements NetworkBridge {
206206
assetId: string,
207207
amount: number,
208208
): Promise<TransactionResponse> {
209-
const fnTag = `${BesuBridge.CLASS_NAME}}#burnAsset`;
209+
const fnTag = `${BesuBridge.CLASS_NAME}#burnAsset`;
210210
this.log.debug(`${fnTag}, Burning Asset: ${assetId} amount: ${amount}`);
211211
const response = (await this.connector.invokeContract({
212212
contractName: this.config.contractName,
@@ -231,7 +231,7 @@ export class BesuBridge implements NetworkBridge {
231231
to: string,
232232
amount: number,
233233
): Promise<TransactionResponse> {
234-
const fnTag = `${BesuBridge.CLASS_NAME}}#assignAsset`;
234+
const fnTag = `${BesuBridge.CLASS_NAME}#assignAsset`;
235235
this.log.debug(
236236
`${fnTag}, Assigning Asset: ${assetId} amount: ${amount} to: ${to}`,
237237
);
@@ -255,7 +255,7 @@ export class BesuBridge implements NetworkBridge {
255255
}
256256

257257
public async getAssets(): Promise<string[]> {
258-
const fnTag = `${BesuBridge.CLASS_NAME}}#getAssets`;
258+
const fnTag = `${BesuBridge.CLASS_NAME}#getAssets`;
259259
this.log.debug(`${fnTag}, Getting Assets`);
260260
const response = (await this.connector.invokeContract({
261261
contractName: this.config.contractName,
@@ -275,7 +275,7 @@ export class BesuBridge implements NetworkBridge {
275275
}
276276

277277
public async getAsset(assetId: string): Promise<EvmAsset> {
278-
const fnTag = `${BesuBridge.CLASS_NAME}}#getAsset`;
278+
const fnTag = `${BesuBridge.CLASS_NAME}#getAsset`;
279279
this.log.debug(`${fnTag}, Getting Asset`);
280280
const response = (await this.connector.invokeContract({
281281
contractName: this.config.contractName,
@@ -303,7 +303,7 @@ export class BesuBridge implements NetworkBridge {
303303
params: string[],
304304
invocationType: EthContractInvocationType,
305305
): Promise<TransactionResponse> {
306-
const fnTag = `${BesuBridge.CLASS_NAME}}#runTransaction`;
306+
const fnTag = `${BesuBridge.CLASS_NAME}#runTransaction`;
307307
this.log.debug(
308308
`${fnTag}, Running Transaction: ${methodName} with params: ${params}`,
309309
);
@@ -362,7 +362,7 @@ export class BesuBridge implements NetworkBridge {
362362
//assetId: string,
363363
transactionId: string,
364364
): Promise<string> {
365-
const fnTag = `${BesuBridge.CLASS_NAME}}#getReceipt`;
365+
const fnTag = `${BesuBridge.CLASS_NAME}#getReceipt`;
366366
this.log.debug(
367367
`${fnTag}, Getting Receipt: transactionId: ${transactionId}`,
368368
);
@@ -406,4 +406,27 @@ export class BesuBridge implements NetworkBridge {
406406

407407
return interactions;
408408
}
409+
410+
/**
411+
* Merges two receipts into one.
412+
*
413+
* @param receipt1 - First receipt to merge.
414+
* @param receipt2 - Second receipt to merge.
415+
* @returns The merged receipt as a string.
416+
*/
417+
merge_receipt(
418+
receipt1: string | undefined,
419+
receipt2: string | undefined,
420+
): string {
421+
if (!receipt1 && !receipt2) return "";
422+
if (!receipt1) return receipt2 as string;
423+
if (!receipt2) return receipt1 as string;
424+
425+
const mergedReceipt = {
426+
...JSON.parse(receipt1 as string),
427+
...JSON.parse(receipt2 as string),
428+
};
429+
430+
return safeStableStringify(mergedReceipt) || "";
431+
}
409432
}

packages/cactus-plugin-satp-hermes/src/main/typescript/cross-chain-mechanisms/satp-bridge/ethereum-bridge.ts

+34-11
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class EthereumBridge implements NetworkBridge {
7171
}
7272

7373
public async wrapAsset(asset: EvmAsset): Promise<TransactionResponse> {
74-
const fnTag = `${EthereumBridge.CLASS_NAME}}#wrapAsset`;
74+
const fnTag = `${EthereumBridge.CLASS_NAME}#wrapAsset`;
7575
this.log.debug(
7676
`${fnTag}, Wrapping Asset: {${asset.tokenId}, ${asset.owner}, ${asset.contractAddress}, ${asset.tokenType}}`,
7777
);
@@ -110,7 +110,7 @@ export class EthereumBridge implements NetworkBridge {
110110
};
111111
}
112112
public async unwrapAsset(assetId: string): Promise<TransactionResponse> {
113-
const fnTag = `${EthereumBridge.CLASS_NAME}}#unwrapAsset`;
113+
const fnTag = `${EthereumBridge.CLASS_NAME}#unwrapAsset`;
114114
this.log.debug(`${fnTag}, Unwrapping Asset: ${assetId}`);
115115
const response = (await this.connector.invokeContract({
116116
contract: {
@@ -135,7 +135,7 @@ export class EthereumBridge implements NetworkBridge {
135135
assetId: string,
136136
amount: number,
137137
): Promise<TransactionResponse> {
138-
const fnTag = `${EthereumBridge.CLASS_NAME}}#lockAsset`;
138+
const fnTag = `${EthereumBridge.CLASS_NAME}#lockAsset`;
139139
this.log.debug(`${fnTag}, Locking Asset: ${assetId} amount: ${amount}`);
140140
const response = (await this.connector.invokeContract({
141141
contract: {
@@ -161,7 +161,7 @@ export class EthereumBridge implements NetworkBridge {
161161
assetId: string,
162162
amount: number,
163163
): Promise<TransactionResponse> {
164-
const fnTag = `${EthereumBridge.CLASS_NAME}}#unlockAsset`;
164+
const fnTag = `${EthereumBridge.CLASS_NAME}#unlockAsset`;
165165
this.log.debug(`${fnTag}, Unlocking Asset: ${assetId} amount: ${amount}`);
166166
const response = (await this.connector.invokeContract({
167167
contract: {
@@ -186,7 +186,7 @@ export class EthereumBridge implements NetworkBridge {
186186
assetId: string,
187187
amount: number,
188188
): Promise<TransactionResponse> {
189-
const fnTag = `${EthereumBridge.CLASS_NAME}}#mintAsset`;
189+
const fnTag = `${EthereumBridge.CLASS_NAME}#mintAsset`;
190190
this.log.debug(`${fnTag}, Minting Asset: ${assetId} amount: ${amount}`);
191191
const response = (await this.connector.invokeContract({
192192
contract: {
@@ -211,7 +211,7 @@ export class EthereumBridge implements NetworkBridge {
211211
assetId: string,
212212
amount: number,
213213
): Promise<TransactionResponse> {
214-
const fnTag = `${EthereumBridge.CLASS_NAME}}#burnAsset`;
214+
const fnTag = `${EthereumBridge.CLASS_NAME}#burnAsset`;
215215
this.log.debug(`${fnTag}, Burning Asset: ${assetId} amount: ${amount}`);
216216
const response = (await this.connector.invokeContract({
217217
contract: {
@@ -237,7 +237,7 @@ export class EthereumBridge implements NetworkBridge {
237237
to: string,
238238
amount: number,
239239
): Promise<TransactionResponse> {
240-
const fnTag = `${EthereumBridge.CLASS_NAME}}#assignAsset`;
240+
const fnTag = `${EthereumBridge.CLASS_NAME}#assignAsset`;
241241
this.log.debug(
242242
`${fnTag}, Assigning Asset: ${assetId} amount: ${amount} to: ${to}`,
243243
);
@@ -262,7 +262,7 @@ export class EthereumBridge implements NetworkBridge {
262262
}
263263

264264
public async getAssets(): Promise<string[]> {
265-
const fnTag = `${EthereumBridge.CLASS_NAME}}#getAssets`;
265+
const fnTag = `${EthereumBridge.CLASS_NAME}#getAssets`;
266266
this.log.debug(`${fnTag}, Getting Assets`);
267267
const response = (await this.connector.invokeContract({
268268
contract: {
@@ -283,7 +283,7 @@ export class EthereumBridge implements NetworkBridge {
283283
}
284284

285285
public async getAsset(assetId: string): Promise<EvmAsset> {
286-
const fnTag = `${EthereumBridge.CLASS_NAME}}#getAsset`;
286+
const fnTag = `${EthereumBridge.CLASS_NAME}#getAsset`;
287287
this.log.debug(`${fnTag}, Getting Asset`);
288288
const response = (await this.connector.invokeContract({
289289
contract: {
@@ -312,7 +312,7 @@ export class EthereumBridge implements NetworkBridge {
312312
params: string[],
313313
invocationType: EthContractInvocationType,
314314
): Promise<TransactionResponse> {
315-
const fnTag = `${EthereumBridge.CLASS_NAME}}#runTransaction`;
315+
const fnTag = `${EthereumBridge.CLASS_NAME}#runTransaction`;
316316
this.log.debug(
317317
`${fnTag}, Running Transaction: ${methodName} with params: ${params}`,
318318
);
@@ -372,7 +372,7 @@ export class EthereumBridge implements NetworkBridge {
372372
//assetId: string,
373373
transactionId: string,
374374
): Promise<string> {
375-
const fnTag = `${EthereumBridge.CLASS_NAME}}#getReceipt`;
375+
const fnTag = `${EthereumBridge.CLASS_NAME}#getReceipt`;
376376
this.log.debug(
377377
`${fnTag}, Getting Receipt: transactionId: ${transactionId}`,
378378
);
@@ -419,4 +419,27 @@ export class EthereumBridge implements NetworkBridge {
419419

420420
return interactions;
421421
}
422+
423+
/**
424+
* Merges two receipts into one.
425+
*
426+
* @param receipt1 - First receipt to merge.
427+
* @param receipt2 - Second receipt to merge.
428+
* @returns The merged receipt as a string.
429+
*/
430+
merge_receipt(
431+
receipt1: string | undefined,
432+
receipt2: string | undefined,
433+
): string {
434+
if (!receipt1 && !receipt2) return "";
435+
if (!receipt1) return receipt2 as string;
436+
if (!receipt2) return receipt1 as string;
437+
438+
const mergedReceipt = {
439+
...JSON.parse(receipt1 as string),
440+
...JSON.parse(receipt2 as string),
441+
};
442+
443+
return safeStableStringify(mergedReceipt) || "";
444+
}
422445
}

0 commit comments

Comments
 (0)