@atomiqlabs/chain-starknet 4.0.0-dev.4 → 4.0.0-dev.5
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/dist/starknet/swaps/EscrowManagerAbi.d.ts +0 -3
- package/dist/starknet/swaps/EscrowManagerAbi.js +0 -4
- package/dist/starknet/swaps/StarknetSwapContract.js +1 -1
- package/dist/starknet/swaps/StarknetSwapData.d.ts +8 -1
- package/dist/starknet/swaps/StarknetSwapData.js +47 -12
- package/dist/starknet/swaps/modules/StarknetSwapClaim.js +3 -3
- package/dist/utils/Utils.js +1 -1
- package/package.json +2 -2
- package/src/starknet/swaps/EscrowManagerAbi.ts +0 -4
- package/src/starknet/swaps/StarknetSwapContract.ts +1 -1
- package/src/starknet/swaps/StarknetSwapData.ts +65 -13
- package/src/starknet/swaps/modules/StarknetSwapClaim.ts +3 -3
- package/src/utils/Utils.ts +1 -1
|
@@ -16,9 +16,6 @@ export declare const EscrowManagerAbi: readonly [{
|
|
|
16
16
|
readonly type: "struct";
|
|
17
17
|
readonly name: "escrow_manager::structs::escrow::EscrowExecution";
|
|
18
18
|
readonly members: readonly [{
|
|
19
|
-
readonly name: "contract";
|
|
20
|
-
readonly type: "core::starknet::contract_address::ContractAddress";
|
|
21
|
-
}, {
|
|
22
19
|
readonly name: "hash";
|
|
23
20
|
readonly type: "core::felt252";
|
|
24
21
|
}, {
|
|
@@ -25,10 +25,6 @@ exports.EscrowManagerAbi = [
|
|
|
25
25
|
"type": "struct",
|
|
26
26
|
"name": "escrow_manager::structs::escrow::EscrowExecution",
|
|
27
27
|
"members": [
|
|
28
|
-
{
|
|
29
|
-
"name": "contract",
|
|
30
|
-
"type": "core::starknet::contract_address::ContractAddress"
|
|
31
|
-
},
|
|
32
28
|
{
|
|
33
29
|
"name": "hash",
|
|
34
30
|
"type": "core::felt252"
|
|
@@ -76,7 +76,7 @@ class StarknetSwapContract extends StarknetContractBase_1.StarknetContractBase {
|
|
|
76
76
|
handlerAddresses.claim = { ...defaultClaimAddresses[chainInterface.starknetChainId], ...handlerAddresses.claim };
|
|
77
77
|
ClaimHandlers_1.claimHandlersList.forEach(handlerCtor => {
|
|
78
78
|
const handler = new handlerCtor(handlerAddresses.claim[handlerCtor.type]);
|
|
79
|
-
this.claimHandlersByAddress[handler.address] = handler;
|
|
79
|
+
this.claimHandlersByAddress[(0, Utils_1.toHex)(handler.address)] = handler;
|
|
80
80
|
this.claimHandlersBySwapType[handlerCtor.type] = handler;
|
|
81
81
|
});
|
|
82
82
|
this.timelockRefundHandler = new TimelockRefundHandler_1.TimelockRefundHandler(handlerAddresses.refund.timelock);
|
|
@@ -4,6 +4,11 @@ import { StringToPrimitiveType } from "abi-wan-kanabi/dist/kanabi";
|
|
|
4
4
|
import { EscrowManagerAbi } from "./EscrowManagerAbi";
|
|
5
5
|
import { IClaimHandler } from "./handlers/claim/ClaimHandlers";
|
|
6
6
|
export type StarknetSwapDataType = StringToPrimitiveType<typeof EscrowManagerAbi, "escrow_manager::structs::escrow::EscrowData">;
|
|
7
|
+
export type StarknetSuccessAction = {
|
|
8
|
+
executionHash: string;
|
|
9
|
+
executionExpiry: bigint;
|
|
10
|
+
executionFee: bigint;
|
|
11
|
+
};
|
|
7
12
|
export declare class StarknetSwapData extends SwapData {
|
|
8
13
|
static toFlags(value: number | bigint | string): {
|
|
9
14
|
payOut: boolean;
|
|
@@ -28,8 +33,9 @@ export declare class StarknetSwapData extends SwapData {
|
|
|
28
33
|
securityDeposit: bigint;
|
|
29
34
|
claimerBounty: bigint;
|
|
30
35
|
extraData: string;
|
|
36
|
+
successAction?: StarknetSuccessAction;
|
|
31
37
|
kind: ChainSwapType;
|
|
32
|
-
constructor(offerer: string, claimer: string, token: string, refundHandler: string, claimHandler: string, payOut: boolean, payIn: boolean, reputation: boolean, sequence: bigint, claimData: string, refundData: string, amount: bigint, feeToken: string, securityDeposit: bigint, claimerBounty: bigint, kind: ChainSwapType, extraData: string);
|
|
38
|
+
constructor(offerer: string, claimer: string, token: string, refundHandler: string, claimHandler: string, payOut: boolean, payIn: boolean, reputation: boolean, sequence: bigint, claimData: string, refundData: string, amount: bigint, feeToken: string, securityDeposit: bigint, claimerBounty: bigint, kind: ChainSwapType, extraData: string, successAction?: StarknetSuccessAction);
|
|
33
39
|
constructor(data: any);
|
|
34
40
|
getOfferer(): string;
|
|
35
41
|
setOfferer(newOfferer: string): void;
|
|
@@ -64,4 +70,5 @@ export declare class StarknetSwapData extends SwapData {
|
|
|
64
70
|
equals(other: StarknetSwapData): boolean;
|
|
65
71
|
toEscrowStruct(): StarknetSwapDataType;
|
|
66
72
|
static fromSerializedFeltArray(span: BigNumberish[], claimHandlerImpl: IClaimHandler<any, any>): StarknetSwapData;
|
|
73
|
+
hasSuccessAction(): boolean;
|
|
67
74
|
}
|
|
@@ -8,6 +8,14 @@ const Utils_1 = require("../../utils/Utils");
|
|
|
8
8
|
const FLAG_PAY_OUT = 0x01n;
|
|
9
9
|
const FLAG_PAY_IN = 0x02n;
|
|
10
10
|
const FLAG_REPUTATION = 0x04n;
|
|
11
|
+
function successActionEquals(a, b) {
|
|
12
|
+
if (a != null && b != null) {
|
|
13
|
+
return a.executionHash.toLowerCase() === b.executionHash.toLowerCase() &&
|
|
14
|
+
a.executionExpiry === b.executionExpiry &&
|
|
15
|
+
a.executionFee === b.executionFee;
|
|
16
|
+
}
|
|
17
|
+
return a === b;
|
|
18
|
+
}
|
|
11
19
|
class StarknetSwapData extends base_1.SwapData {
|
|
12
20
|
static toFlags(value) {
|
|
13
21
|
const val = (0, Utils_1.toBigInt)(value);
|
|
@@ -24,7 +32,7 @@ class StarknetSwapData extends base_1.SwapData {
|
|
|
24
32
|
(this.payIn ? FLAG_PAY_IN : 0n) +
|
|
25
33
|
(this.reputation ? FLAG_REPUTATION : 0n);
|
|
26
34
|
}
|
|
27
|
-
constructor(offererOrData, claimer, token, refundHandler, claimHandler, payOut, payIn, reputation, sequence, claimData, refundData, amount, feeToken, securityDeposit, claimerBounty, kind, extraData) {
|
|
35
|
+
constructor(offererOrData, claimer, token, refundHandler, claimHandler, payOut, payIn, reputation, sequence, claimData, refundData, amount, feeToken, securityDeposit, claimerBounty, kind, extraData, successAction) {
|
|
28
36
|
super();
|
|
29
37
|
if (claimer != null || token != null || refundHandler != null || claimHandler != null ||
|
|
30
38
|
payOut != null || payIn != null || reputation != null || sequence != null || claimData != null || refundData != null ||
|
|
@@ -46,6 +54,7 @@ class StarknetSwapData extends base_1.SwapData {
|
|
|
46
54
|
this.claimerBounty = claimerBounty;
|
|
47
55
|
this.kind = kind;
|
|
48
56
|
this.extraData = extraData;
|
|
57
|
+
this.successAction = successAction;
|
|
49
58
|
}
|
|
50
59
|
else {
|
|
51
60
|
this.offerer = offererOrData.offerer;
|
|
@@ -65,6 +74,11 @@ class StarknetSwapData extends base_1.SwapData {
|
|
|
65
74
|
this.claimerBounty = offererOrData.claimerBounty == null ? null : BigInt(offererOrData.claimerBounty);
|
|
66
75
|
this.kind = offererOrData.kind;
|
|
67
76
|
this.extraData = offererOrData.extraData;
|
|
77
|
+
this.successAction = offererOrData.successAction == null ? null : {
|
|
78
|
+
executionHash: offererOrData.successAction.executionHash,
|
|
79
|
+
executionExpiry: BigInt(offererOrData.successAction.executionExpiry),
|
|
80
|
+
executionFee: BigInt(offererOrData.successAction.executionFee),
|
|
81
|
+
};
|
|
68
82
|
}
|
|
69
83
|
}
|
|
70
84
|
getOfferer() {
|
|
@@ -102,7 +116,12 @@ class StarknetSwapData extends base_1.SwapData {
|
|
|
102
116
|
securityDeposit: this.securityDeposit == null ? null : this.securityDeposit.toString(10),
|
|
103
117
|
claimerBounty: this.claimerBounty == null ? null : this.claimerBounty.toString(10),
|
|
104
118
|
kind: this.kind,
|
|
105
|
-
extraData: this.extraData
|
|
119
|
+
extraData: this.extraData,
|
|
120
|
+
successAction: this.successAction == null ? null : {
|
|
121
|
+
executionHash: this.successAction.executionHash,
|
|
122
|
+
executionExpiry: this.successAction.executionExpiry.toString(10),
|
|
123
|
+
executionFee: this.successAction.executionFee.toString(10)
|
|
124
|
+
}
|
|
106
125
|
};
|
|
107
126
|
}
|
|
108
127
|
getAmount() {
|
|
@@ -130,7 +149,7 @@ class StarknetSwapData extends base_1.SwapData {
|
|
|
130
149
|
const amountValue = starknet_1.cairo.uint256("0x" + this.amount.toString(16));
|
|
131
150
|
const securityDepositValue = starknet_1.cairo.uint256("0x" + this.securityDeposit.toString(16));
|
|
132
151
|
const claimerBountyValue = starknet_1.cairo.uint256("0x" + this.claimerBounty.toString(16));
|
|
133
|
-
|
|
152
|
+
const elements = [
|
|
134
153
|
this.offerer,
|
|
135
154
|
this.claimer,
|
|
136
155
|
this.token,
|
|
@@ -146,7 +165,14 @@ class StarknetSwapData extends base_1.SwapData {
|
|
|
146
165
|
securityDepositValue.high,
|
|
147
166
|
claimerBountyValue.low,
|
|
148
167
|
claimerBountyValue.high
|
|
149
|
-
]
|
|
168
|
+
];
|
|
169
|
+
if (this.successAction != null) {
|
|
170
|
+
elements.push(this.successAction.executionHash);
|
|
171
|
+
elements.push(this.successAction.executionExpiry);
|
|
172
|
+
const feeValue = starknet_1.cairo.uint256("0x" + this.successAction.executionFee.toString(16));
|
|
173
|
+
elements.push(feeValue.low, feeValue.high);
|
|
174
|
+
}
|
|
175
|
+
let escrowHash = starknet_1.hash.computePoseidonHashOnElements(elements);
|
|
150
176
|
if (escrowHash.startsWith("0x"))
|
|
151
177
|
escrowHash = escrowHash.slice(2);
|
|
152
178
|
return escrowHash.padStart(64, "0");
|
|
@@ -243,7 +269,8 @@ class StarknetSwapData extends base_1.SwapData {
|
|
|
243
269
|
other.refundData.toLowerCase() === this.refundData.toLowerCase() &&
|
|
244
270
|
other.amount === this.amount &&
|
|
245
271
|
other.securityDeposit === this.securityDeposit &&
|
|
246
|
-
other.claimerBounty === this.claimerBounty
|
|
272
|
+
other.claimerBounty === this.claimerBounty &&
|
|
273
|
+
successActionEquals(other.successAction, this.successAction);
|
|
247
274
|
}
|
|
248
275
|
toEscrowStruct() {
|
|
249
276
|
return {
|
|
@@ -259,7 +286,11 @@ class StarknetSwapData extends base_1.SwapData {
|
|
|
259
286
|
fee_token: this.feeToken,
|
|
260
287
|
security_deposit: starknet_1.cairo.uint256((0, Utils_1.toBigInt)(this.securityDeposit)),
|
|
261
288
|
claimer_bounty: starknet_1.cairo.uint256((0, Utils_1.toBigInt)(this.claimerBounty)),
|
|
262
|
-
success_action: new starknet_1.CairoOption(starknet_1.CairoOptionVariant.None
|
|
289
|
+
success_action: new starknet_1.CairoOption(this.successAction == null ? starknet_1.CairoOptionVariant.None : starknet_1.CairoOptionVariant.Some, this.successAction == null ? undefined : {
|
|
290
|
+
hash: this.successAction.executionHash,
|
|
291
|
+
expiry: this.successAction.executionExpiry,
|
|
292
|
+
fee: starknet_1.cairo.uint256(this.successAction.executionFee)
|
|
293
|
+
})
|
|
263
294
|
};
|
|
264
295
|
}
|
|
265
296
|
static fromSerializedFeltArray(span, claimHandlerImpl) {
|
|
@@ -276,14 +307,18 @@ class StarknetSwapData extends base_1.SwapData {
|
|
|
276
307
|
const securityDeposit = (0, Utils_1.toBigInt)({ low: span.shift(), high: span.shift() });
|
|
277
308
|
const claimerBounty = (0, Utils_1.toBigInt)({ low: span.shift(), high: span.shift() });
|
|
278
309
|
const hasSuccessAction = (0, Utils_1.toBigInt)(span.shift()) === 0n;
|
|
310
|
+
let successAction = null;
|
|
279
311
|
if (hasSuccessAction) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
312
|
+
successAction = {
|
|
313
|
+
executionHash: (0, Utils_1.toHex)(span.shift()),
|
|
314
|
+
executionExpiry: (0, Utils_1.toBigInt)(span.shift()),
|
|
315
|
+
executionFee: (0, Utils_1.toBigInt)({ low: span.shift(), high: span.shift() })
|
|
316
|
+
};
|
|
285
317
|
}
|
|
286
|
-
return new StarknetSwapData(offerer, claimer, token, refundHandler, claimHandler, payOut, payIn, reputation, sequence, claimData, refundData, amount, feeToken, securityDeposit, claimerBounty, claimHandlerImpl.getType(), null);
|
|
318
|
+
return new StarknetSwapData(offerer, claimer, token, refundHandler, claimHandler, payOut, payIn, reputation, sequence, claimData, refundData, amount, feeToken, securityDeposit, claimerBounty, claimHandlerImpl.getType(), null, successAction);
|
|
319
|
+
}
|
|
320
|
+
hasSuccessAction() {
|
|
321
|
+
return this.successAction != null;
|
|
287
322
|
}
|
|
288
323
|
}
|
|
289
324
|
exports.StarknetSwapData = StarknetSwapData;
|
|
@@ -36,7 +36,7 @@ class StarknetSwapClaim extends StarknetSwapModule_1.StarknetSwapModule {
|
|
|
36
36
|
if (checkExpiry && await this.contract.isExpired(swapData.claimer.toString(), swapData)) {
|
|
37
37
|
throw new base_1.SwapDataVerificationError("Not enough time to reliably pay the invoice");
|
|
38
38
|
}
|
|
39
|
-
const claimHandler = this.contract.claimHandlersByAddress[swapData.claimHandler
|
|
39
|
+
const claimHandler = this.contract.claimHandlersByAddress[(0, Utils_1.toHex)(swapData.claimHandler)];
|
|
40
40
|
if (claimHandler == null)
|
|
41
41
|
throw new base_1.SwapDataVerificationError("Unknown claim handler!");
|
|
42
42
|
if (claimHandler.getType() !== base_1.ChainSwapType.HTLC)
|
|
@@ -61,7 +61,7 @@ class StarknetSwapClaim extends StarknetSwapModule_1.StarknetSwapModule {
|
|
|
61
61
|
* @param feeRate fee rate to be used for the transactions
|
|
62
62
|
*/
|
|
63
63
|
async txsClaimWithTxData(signer, swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, feeRate) {
|
|
64
|
-
const claimHandler = this.contract.claimHandlersByAddress[swapData.claimHandler
|
|
64
|
+
const claimHandler = this.contract.claimHandlersByAddress[(0, Utils_1.toHex)(swapData.claimHandler)];
|
|
65
65
|
if (claimHandler == null)
|
|
66
66
|
throw new base_1.SwapDataVerificationError("Unknown claim handler!");
|
|
67
67
|
if (claimHandler.getType() !== base_1.ChainSwapType.CHAIN_NONCED &&
|
|
@@ -87,7 +87,7 @@ class StarknetSwapClaim extends StarknetSwapModule_1.StarknetSwapModule {
|
|
|
87
87
|
async getClaimFee(swapData, feeRate) {
|
|
88
88
|
feeRate ?? (feeRate = await this.root.Fees.getFeeRate());
|
|
89
89
|
let gasRequired = swapData.payOut ? StarknetSwapClaim.GasCosts.CLAIM_PAY_OUT : StarknetSwapClaim.GasCosts.CLAIM;
|
|
90
|
-
const claimHandler = this.contract.claimHandlersByAddress[swapData.claimHandler
|
|
90
|
+
const claimHandler = this.contract.claimHandlersByAddress[(0, Utils_1.toHex)(swapData.claimHandler)];
|
|
91
91
|
if (claimHandler != null)
|
|
92
92
|
gasRequired = (0, StarknetFees_1.starknetGasAdd)(gasRequired, claimHandler.getGas(swapData));
|
|
93
93
|
return StarknetFees_1.StarknetFees.getGasFee(gasRequired, feeRate);
|
package/dist/utils/Utils.js
CHANGED
|
@@ -79,7 +79,7 @@ function toHex(value, length = 64) {
|
|
|
79
79
|
switch (typeof (value)) {
|
|
80
80
|
case "string":
|
|
81
81
|
if (value.startsWith("0x")) {
|
|
82
|
-
return "0x" + value.slice(2).padStart(length, "0");
|
|
82
|
+
return "0x" + value.slice(2).padStart(length, "0").toLowerCase();
|
|
83
83
|
}
|
|
84
84
|
else {
|
|
85
85
|
return "0x" + BigInt(value).toString(16).padStart(length, "0");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomiqlabs/chain-starknet",
|
|
3
|
-
"version": "4.0.0-dev.
|
|
3
|
+
"version": "4.0.0-dev.5",
|
|
4
4
|
"description": "Starknet specific base implementation",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types:": "./dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"author": "adambor",
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@atomiqlabs/base": "^10.0.0-dev.
|
|
25
|
+
"@atomiqlabs/base": "^10.0.0-dev.8",
|
|
26
26
|
"@noble/hashes": "^1.7.1",
|
|
27
27
|
"@scure/btc-signer": "1.6.0",
|
|
28
28
|
"abi-wan-kanabi": "2.2.4",
|
|
@@ -22,10 +22,6 @@ export const EscrowManagerAbi = [
|
|
|
22
22
|
"type": "struct",
|
|
23
23
|
"name": "escrow_manager::structs::escrow::EscrowExecution",
|
|
24
24
|
"members": [
|
|
25
|
-
{
|
|
26
|
-
"name": "contract",
|
|
27
|
-
"type": "core::starknet::contract_address::ContractAddress"
|
|
28
|
-
},
|
|
29
25
|
{
|
|
30
26
|
"name": "hash",
|
|
31
27
|
"type": "core::felt252"
|
|
@@ -134,7 +134,7 @@ export class StarknetSwapContract
|
|
|
134
134
|
|
|
135
135
|
claimHandlersList.forEach(handlerCtor => {
|
|
136
136
|
const handler = new handlerCtor(handlerAddresses.claim[handlerCtor.type]);
|
|
137
|
-
this.claimHandlersByAddress[handler.address] = handler;
|
|
137
|
+
this.claimHandlersByAddress[toHex(handler.address)] = handler;
|
|
138
138
|
this.claimHandlersBySwapType[handlerCtor.type] = handler;
|
|
139
139
|
});
|
|
140
140
|
|
|
@@ -14,6 +14,21 @@ const FLAG_REPUTATION: bigint = 0x04n;
|
|
|
14
14
|
|
|
15
15
|
export type StarknetSwapDataType = StringToPrimitiveType<typeof EscrowManagerAbi, "escrow_manager::structs::escrow::EscrowData">;
|
|
16
16
|
|
|
17
|
+
export type StarknetSuccessAction = {
|
|
18
|
+
executionHash: string,
|
|
19
|
+
executionExpiry: bigint,
|
|
20
|
+
executionFee: bigint
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function successActionEquals(a: StarknetSuccessAction, b: StarknetSuccessAction): boolean {
|
|
24
|
+
if(a!=null && b!=null) {
|
|
25
|
+
return a.executionHash.toLowerCase()===b.executionHash.toLowerCase() &&
|
|
26
|
+
a.executionExpiry === b.executionExpiry &&
|
|
27
|
+
a.executionFee === b.executionFee;
|
|
28
|
+
}
|
|
29
|
+
return a === b;
|
|
30
|
+
}
|
|
31
|
+
|
|
17
32
|
export class StarknetSwapData extends SwapData {
|
|
18
33
|
|
|
19
34
|
static toFlags(value: number | bigint | string): {payOut: boolean, payIn: boolean, reputation: boolean, sequence: bigint} {
|
|
@@ -57,6 +72,8 @@ export class StarknetSwapData extends SwapData {
|
|
|
57
72
|
|
|
58
73
|
extraData: string;
|
|
59
74
|
|
|
75
|
+
successAction?: StarknetSuccessAction;
|
|
76
|
+
|
|
60
77
|
kind: ChainSwapType;
|
|
61
78
|
|
|
62
79
|
constructor(
|
|
@@ -76,7 +93,8 @@ export class StarknetSwapData extends SwapData {
|
|
|
76
93
|
securityDeposit: bigint,
|
|
77
94
|
claimerBounty: bigint,
|
|
78
95
|
kind: ChainSwapType,
|
|
79
|
-
extraData: string
|
|
96
|
+
extraData: string,
|
|
97
|
+
successAction?: StarknetSuccessAction
|
|
80
98
|
);
|
|
81
99
|
|
|
82
100
|
constructor(data: any);
|
|
@@ -98,7 +116,8 @@ export class StarknetSwapData extends SwapData {
|
|
|
98
116
|
securityDeposit?: bigint,
|
|
99
117
|
claimerBounty?: bigint,
|
|
100
118
|
kind?: ChainSwapType,
|
|
101
|
-
extraData?: string
|
|
119
|
+
extraData?: string,
|
|
120
|
+
successAction?: StarknetSuccessAction
|
|
102
121
|
) {
|
|
103
122
|
super();
|
|
104
123
|
if(claimer!=null || token!=null || refundHandler!=null || claimHandler!=null ||
|
|
@@ -121,6 +140,7 @@ export class StarknetSwapData extends SwapData {
|
|
|
121
140
|
this.claimerBounty = claimerBounty;
|
|
122
141
|
this.kind = kind;
|
|
123
142
|
this.extraData = extraData;
|
|
143
|
+
this.successAction = successAction;
|
|
124
144
|
} else {
|
|
125
145
|
this.offerer = offererOrData.offerer;
|
|
126
146
|
this.claimer = offererOrData.claimer;
|
|
@@ -139,6 +159,11 @@ export class StarknetSwapData extends SwapData {
|
|
|
139
159
|
this.claimerBounty = offererOrData.claimerBounty==null ? null : BigInt(offererOrData.claimerBounty);
|
|
140
160
|
this.kind = offererOrData.kind;
|
|
141
161
|
this.extraData = offererOrData.extraData;
|
|
162
|
+
this.successAction = offererOrData.successAction==null ? null : {
|
|
163
|
+
executionHash: offererOrData.successAction.executionHash,
|
|
164
|
+
executionExpiry: BigInt(offererOrData.successAction.executionExpiry),
|
|
165
|
+
executionFee: BigInt(offererOrData.successAction.executionFee),
|
|
166
|
+
}
|
|
142
167
|
}
|
|
143
168
|
}
|
|
144
169
|
|
|
@@ -181,7 +206,12 @@ export class StarknetSwapData extends SwapData {
|
|
|
181
206
|
securityDeposit: this.securityDeposit==null ? null : this.securityDeposit.toString(10),
|
|
182
207
|
claimerBounty: this.claimerBounty==null ? null : this.claimerBounty.toString(10),
|
|
183
208
|
kind: this.kind,
|
|
184
|
-
extraData: this.extraData
|
|
209
|
+
extraData: this.extraData,
|
|
210
|
+
successAction: this.successAction==null ? null : {
|
|
211
|
+
executionHash: this.successAction.executionHash,
|
|
212
|
+
executionExpiry: this.successAction.executionExpiry.toString(10),
|
|
213
|
+
executionFee: this.successAction.executionFee.toString(10)
|
|
214
|
+
}
|
|
185
215
|
}
|
|
186
216
|
}
|
|
187
217
|
|
|
@@ -217,7 +247,7 @@ export class StarknetSwapData extends SwapData {
|
|
|
217
247
|
const amountValue = cairo.uint256("0x"+this.amount.toString(16));
|
|
218
248
|
const securityDepositValue = cairo.uint256("0x"+this.securityDeposit.toString(16));
|
|
219
249
|
const claimerBountyValue = cairo.uint256("0x"+this.claimerBounty.toString(16));
|
|
220
|
-
|
|
250
|
+
const elements = [
|
|
221
251
|
this.offerer,
|
|
222
252
|
this.claimer,
|
|
223
253
|
this.token,
|
|
@@ -233,7 +263,15 @@ export class StarknetSwapData extends SwapData {
|
|
|
233
263
|
securityDepositValue.high,
|
|
234
264
|
claimerBountyValue.low,
|
|
235
265
|
claimerBountyValue.high
|
|
236
|
-
]
|
|
266
|
+
];
|
|
267
|
+
if(this.successAction!=null) {
|
|
268
|
+
elements.push(this.successAction.executionHash);
|
|
269
|
+
elements.push(this.successAction.executionExpiry);
|
|
270
|
+
const feeValue = cairo.uint256("0x"+this.successAction.executionFee.toString(16));
|
|
271
|
+
elements.push(feeValue.low, feeValue.high);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
let escrowHash = hash.computePoseidonHashOnElements(elements);
|
|
237
275
|
if(escrowHash.startsWith("0x")) escrowHash = escrowHash.slice(2);
|
|
238
276
|
return escrowHash.padStart(64, "0");
|
|
239
277
|
}
|
|
@@ -334,7 +372,8 @@ export class StarknetSwapData extends SwapData {
|
|
|
334
372
|
other.refundData.toLowerCase()===this.refundData.toLowerCase() &&
|
|
335
373
|
other.amount === this.amount &&
|
|
336
374
|
other.securityDeposit === this.securityDeposit &&
|
|
337
|
-
other.claimerBounty === this.claimerBounty
|
|
375
|
+
other.claimerBounty === this.claimerBounty &&
|
|
376
|
+
successActionEquals(other.successAction, this.successAction)
|
|
338
377
|
}
|
|
339
378
|
|
|
340
379
|
toEscrowStruct(): StarknetSwapDataType {
|
|
@@ -351,7 +390,14 @@ export class StarknetSwapData extends SwapData {
|
|
|
351
390
|
fee_token: this.feeToken,
|
|
352
391
|
security_deposit: cairo.uint256(toBigInt(this.securityDeposit)),
|
|
353
392
|
claimer_bounty: cairo.uint256(toBigInt(this.claimerBounty)),
|
|
354
|
-
success_action: new CairoOption(
|
|
393
|
+
success_action: new CairoOption(
|
|
394
|
+
this.successAction==null ? CairoOptionVariant.None : CairoOptionVariant.Some,
|
|
395
|
+
this.successAction==null ? undefined : {
|
|
396
|
+
hash: this.successAction.executionHash,
|
|
397
|
+
expiry: this.successAction.executionExpiry,
|
|
398
|
+
fee: cairo.uint256(this.successAction.executionFee)
|
|
399
|
+
}
|
|
400
|
+
) as StarknetSwapDataType["success_action"]
|
|
355
401
|
}
|
|
356
402
|
}
|
|
357
403
|
|
|
@@ -369,12 +415,13 @@ export class StarknetSwapData extends SwapData {
|
|
|
369
415
|
const securityDeposit = toBigInt({low: span.shift(), high: span.shift()});
|
|
370
416
|
const claimerBounty = toBigInt({low: span.shift(), high: span.shift()});
|
|
371
417
|
const hasSuccessAction = toBigInt(span.shift()) === 0n;
|
|
418
|
+
let successAction: StarknetSuccessAction = null;
|
|
372
419
|
if(hasSuccessAction) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
420
|
+
successAction = {
|
|
421
|
+
executionHash: toHex(span.shift()),
|
|
422
|
+
executionExpiry: toBigInt(span.shift()),
|
|
423
|
+
executionFee: toBigInt({low: span.shift(), high: span.shift()})
|
|
424
|
+
}
|
|
378
425
|
}
|
|
379
426
|
|
|
380
427
|
return new StarknetSwapData(
|
|
@@ -394,10 +441,15 @@ export class StarknetSwapData extends SwapData {
|
|
|
394
441
|
securityDeposit,
|
|
395
442
|
claimerBounty,
|
|
396
443
|
claimHandlerImpl.getType(),
|
|
397
|
-
null
|
|
444
|
+
null,
|
|
445
|
+
successAction
|
|
398
446
|
);
|
|
399
447
|
}
|
|
400
448
|
|
|
449
|
+
hasSuccessAction(): boolean {
|
|
450
|
+
return this.successAction != null;
|
|
451
|
+
}
|
|
452
|
+
|
|
401
453
|
}
|
|
402
454
|
|
|
403
455
|
SwapData.deserializers["strk"] = StarknetSwapData;
|
|
@@ -64,7 +64,7 @@ export class StarknetSwapClaim extends StarknetSwapModule {
|
|
|
64
64
|
throw new SwapDataVerificationError("Not enough time to reliably pay the invoice");
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
const claimHandler: IClaimHandler<Buffer, string> = this.contract.claimHandlersByAddress[swapData.claimHandler
|
|
67
|
+
const claimHandler: IClaimHandler<Buffer, string> = this.contract.claimHandlersByAddress[toHex(swapData.claimHandler)];
|
|
68
68
|
if(claimHandler==null) throw new SwapDataVerificationError("Unknown claim handler!");
|
|
69
69
|
if(claimHandler.getType()!==ChainSwapType.HTLC) throw new SwapDataVerificationError("Invalid claim handler!");
|
|
70
70
|
|
|
@@ -101,7 +101,7 @@ export class StarknetSwapClaim extends StarknetSwapModule {
|
|
|
101
101
|
synchronizer?: RelaySynchronizer<StarknetBtcStoredHeader, StarknetTx, any>,
|
|
102
102
|
feeRate?: string
|
|
103
103
|
): Promise<StarknetTx[] | null> {
|
|
104
|
-
const claimHandler: IClaimHandler<any, BitcoinOutputWitnessData | BitcoinWitnessData> = this.contract.claimHandlersByAddress[swapData.claimHandler
|
|
104
|
+
const claimHandler: IClaimHandler<any, BitcoinOutputWitnessData | BitcoinWitnessData> = this.contract.claimHandlersByAddress[toHex(swapData.claimHandler)];
|
|
105
105
|
if(claimHandler==null) throw new SwapDataVerificationError("Unknown claim handler!");
|
|
106
106
|
if(
|
|
107
107
|
claimHandler.getType()!==ChainSwapType.CHAIN_NONCED &&
|
|
@@ -133,7 +133,7 @@ export class StarknetSwapClaim extends StarknetSwapModule {
|
|
|
133
133
|
|
|
134
134
|
let gasRequired = swapData.payOut ? StarknetSwapClaim.GasCosts.CLAIM_PAY_OUT : StarknetSwapClaim.GasCosts.CLAIM;
|
|
135
135
|
|
|
136
|
-
const claimHandler: IClaimHandler<any, any> = this.contract.claimHandlersByAddress[swapData.claimHandler
|
|
136
|
+
const claimHandler: IClaimHandler<any, any> = this.contract.claimHandlersByAddress[toHex(swapData.claimHandler)];
|
|
137
137
|
if(claimHandler!=null) gasRequired = starknetGasAdd(gasRequired, claimHandler.getGas(swapData));
|
|
138
138
|
|
|
139
139
|
return StarknetFees.getGasFee(gasRequired, feeRate);
|
package/src/utils/Utils.ts
CHANGED
|
@@ -83,7 +83,7 @@ export function toHex(value: number | bigint | string | Buffer, length: number =
|
|
|
83
83
|
switch(typeof(value)) {
|
|
84
84
|
case "string":
|
|
85
85
|
if(value.startsWith("0x")) {
|
|
86
|
-
return "0x"+value.slice(2).padStart(length, "0");
|
|
86
|
+
return "0x"+value.slice(2).padStart(length, "0").toLowerCase();
|
|
87
87
|
} else {
|
|
88
88
|
return "0x"+BigInt(value).toString(16).padStart(length, "0");
|
|
89
89
|
}
|