Skip to content

Commit 142e031

Browse files
authored
refactor(vechain): remove thor-devkit dependency, inline transaction types, update validation schema (add comment/abi, maxFeePerGas, make gasPriceCoef optional) (#486)
1 parent b5ced58 commit 142e031

File tree

5 files changed

+198
-187
lines changed

5 files changed

+198
-187
lines changed

.changeset/hip-rats-divide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ledgerhq/wallet-api-core": minor
3+
---
4+
5+
refactor(vechain): remove thor-devkit dependency, inline transaction types, update validation schema (add comment/abi, maxFeePerGas, make gasPriceCoef optional)

packages/core/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"@stacks/transactions": "^6.13.0",
3636
"@ton/core": "^0.62.0",
3737
"bignumber.js": "^9.1.2",
38-
"thor-devkit": "^2.0.9",
3938
"uuid": "^9.0.1",
4039
"zod": "^3.22.4"
4140
}
Lines changed: 131 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,141 @@
1-
import type { Transaction as ThorTransaction } from "thor-devkit";
21
import type { z } from "zod";
32
import type { TransactionCommon } from "../index";
43
import type { schemaRawVechainTransaction } from "./validation";
54

65
export type VechainTransaction = TransactionCommon & {
76
readonly family: RawVechainTransaction["family"];
87
estimatedFees: string;
9-
body: ThorTransaction.Body;
8+
body: TransactionBody;
109
};
1110

1211
export type RawVechainTransaction = z.infer<typeof schemaRawVechainTransaction>;
12+
13+
// Copied vechain-sdk-js
14+
// https://github.com/vechain/vechain-sdk-js/blob/main/packages/core/src/transaction/TransactionClause.d.ts
15+
type TransactionClause = {
16+
/**
17+
* Destination address where:
18+
* * transfer token to or
19+
* * invoke contract method on.
20+
*
21+
* @note Set null destination to deploy a contract.
22+
*/
23+
to: string | null;
24+
25+
/**
26+
* Amount of token to transfer to the destination
27+
*/
28+
value: string | number;
29+
30+
/**
31+
* Input data for contract method invocation or deployment
32+
*/
33+
data: string;
34+
35+
/**
36+
* Optional comment for the clause, helpful for displaying what the clause is doing.
37+
*/
38+
comment?: string;
39+
40+
/**
41+
* Optional ABI for the contract method invocation.
42+
*/
43+
abi?: string;
44+
};
45+
46+
// Copied vechain-sdk-js
47+
// https://github.com/vechain/vechain-sdk-js/blob/main/packages/core/src/transaction/TransactionBody.d.ts
48+
type TransactionBody = {
49+
/**
50+
* Last byte of genesis block ID
51+
*/
52+
chainTag: number;
53+
54+
/**
55+
* 8 bytes prefix of some block's ID
56+
*/
57+
blockRef: string;
58+
59+
/**
60+
* Constraint of time bucket
61+
*/
62+
expiration: number;
63+
64+
/**
65+
* Array of clauses
66+
*/
67+
clauses: TransactionClause[];
68+
69+
/**
70+
* Coefficient applied to base gas price [0,255]
71+
*/
72+
gasPriceCoef?: number;
73+
74+
/**
75+
* Max gas provided for execution
76+
*/
77+
gas: string | number;
78+
79+
/**
80+
* ID of another tx that is depended
81+
*/
82+
dependsOn: string | null;
83+
84+
/**
85+
* Nonce value for various purposes.
86+
* Basic is to prevent replay attack by make transaction unique.
87+
* Every transaction with same chainTag, blockRef, ... must have different nonce.
88+
*/
89+
nonce: string | number;
90+
91+
/**
92+
* The maximum fee per gas for the transaction.
93+
*/
94+
maxFeePerGas?: string | number;
95+
96+
/**
97+
* The maximum priority fee per gas for the transaction.
98+
*/
99+
maxPriorityFeePerGas?: string | number;
100+
101+
/**
102+
* A reserved field intended for features use.
103+
*
104+
* In standard EVM transactions, this reserved field typically is not present.
105+
* However, it's been designed to cater to VIP-191, which deals with fee delegation.
106+
*
107+
* If the `features` within the `reserved` field is set as `1111...111`, it indicates that the transaction has been delegated.
108+
* The method to check if the transaction is delegated is:
109+
*
110+
* ```typescript
111+
* reserved.features & 1 === 1
112+
* ```
113+
*
114+
* @example
115+
*
116+
* 1.
117+
* ```typescript
118+
* feature = 111101;
119+
* isDelegated = (111101 & 111111) === 111101; // false (not delegated)
120+
* ```
121+
*
122+
* 2.
123+
* ```typescript
124+
* feature = 111111;
125+
* isDelegated = (111111 & 111111) === 111111; // true (delegated)
126+
* ```
127+
*
128+
* @remarks
129+
* For more information on the subject, refer to {@link https://github.com/vechain/VIPs/blob/master/vips/VIP-191.md | VIP-191}.
130+
*/
131+
reserved?: {
132+
/**
133+
* Tx feature bits
134+
*/
135+
features?: number;
136+
/**
137+
* Unused
138+
*/
139+
unused?: Uint8Array[];
140+
};
141+
};

packages/core/src/families/vechain/validation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export const schemaThorTransactionClause = z.object({
66
to: z.string().nullable(),
77
value: z.union([z.string(), z.number()]),
88
data: z.string(),
9+
comment: z.string().optional(),
10+
abi: z.string().optional(),
911
});
1012

1113
// Generated from VeChain Thor Transaction types
@@ -15,10 +17,12 @@ export const schemaThorTransactionBody = z.object({
1517
blockRef: z.string(),
1618
expiration: z.number(),
1719
clauses: z.array(schemaThorTransactionClause),
18-
gasPriceCoef: z.number(),
20+
gasPriceCoef: z.number().optional(),
1921
gas: z.union([z.string(), z.number()]),
2022
dependsOn: z.string().nullable(),
2123
nonce: z.union([z.string(), z.number()]),
24+
maxFeePerGas: z.union([z.string(), z.number()]).optional(),
25+
maxPriorityFeePerGas: z.union([z.string(), z.number()]).optional(),
2226
reserved: z
2327
.object({
2428
features: z.number().optional(),

0 commit comments

Comments
 (0)