Skip to content

Commit f6f5cd3

Browse files
authored
feat(ton): add named payload types and raw schemas for pool & vesting operations (#484)
1 parent 374c903 commit f6f5cd3

File tree

7 files changed

+493
-30
lines changed

7 files changed

+493
-30
lines changed

.changeset/empty-beers-taste.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+
feat(ton): add named payload types and raw schemas for pool & vesting operations

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"dependencies": {
3434
"@ledgerhq/errors": "^6.16.2",
3535
"@stacks/transactions": "^6.13.0",
36-
"@ton/core": "^0.60.1",
36+
"@ton/core": "^0.62.0",
3737
"bignumber.js": "^9.1.2",
3838
"thor-devkit": "^2.0.9",
3939
"uuid": "^9.0.1",

packages/core/src/families/ton/serializer.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,28 @@ const fromTransactionPayloadRaw = (
153153
queryId: payload.queryId ? BigInt(payload.queryId) : null,
154154
swapId: Buffer.from(payload.swapId, "hex"),
155155
};
156+
case "tonwhales-pool-deposit":
157+
return {
158+
type: payload.type,
159+
queryId: BigInt(payload.queryId),
160+
gasLimit: BigInt(payload.gasLimit),
161+
};
162+
case "tonwhales-pool-withdraw":
163+
return {
164+
type: payload.type,
165+
queryId: BigInt(payload.queryId),
166+
gasLimit: BigInt(payload.gasLimit),
167+
amount: BigInt(payload.amount),
168+
};
169+
case "vesting-send-msg-comment":
170+
return {
171+
type: payload.type,
172+
queryId: payload.queryId ? BigInt(payload.queryId) : null,
173+
sendMode: payload.sendMode,
174+
value: BigInt(payload.value),
175+
destination: Address.parse(payload.destination),
176+
text: payload.text,
177+
};
156178
case "comment":
157179
return payload;
158180
default: {
@@ -299,6 +321,31 @@ const toTransactionPayloadRaw = (
299321
: null,
300322
swapId: payload.swapId.toString("hex"),
301323
};
324+
case "tonwhales-pool-deposit":
325+
return {
326+
type: payload.type,
327+
queryId: payload.queryId.toString(),
328+
gasLimit: payload.gasLimit.toString(),
329+
};
330+
case "tonwhales-pool-withdraw":
331+
return {
332+
type: payload.type,
333+
queryId: payload.queryId.toString(),
334+
gasLimit: payload.gasLimit.toString(),
335+
amount: payload.amount.toString(),
336+
};
337+
case "vesting-send-msg-comment":
338+
return {
339+
type: payload.type,
340+
queryId:
341+
typeof payload.queryId === "bigint"
342+
? payload.queryId.toString()
343+
: null,
344+
sendMode: payload.sendMode,
345+
value: payload.value.toString(),
346+
destination: payload.destination.toRawString(),
347+
text: payload.text,
348+
};
302349
case "comment":
303350
return payload;
304351
default: {

packages/core/src/families/ton/types.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import type {
1616
schemaTonPayloadSingleNominatorWithdrawRaw,
1717
schemaTonPayloadTokenBridgePaySwapRaw,
1818
schemaTonPayloadTonStakersDepositRaw,
19+
schemaTonPayloadTonWhalesPoolDepositRaw,
20+
schemaTonPayloadTonWhalesPoolWithdrawRaw,
1921
schemaTonPayloadUnsafeRaw,
22+
schemaTonPayloadVestingSendMsgCommentRaw,
2023
schemaTonPayloadVoteForProposalRaw,
2124
} from "./validation";
2225

@@ -177,6 +180,40 @@ export type TonPayloadTokenBridgePaySwapRaw = z.infer<
177180
typeof schemaTonPayloadTokenBridgePaySwapRaw
178181
>;
179182

183+
export type TonPayloadTonWhalesPoolDeposit = {
184+
type: "tonwhales-pool-deposit";
185+
queryId: bigint;
186+
gasLimit: bigint;
187+
};
188+
189+
export type TonPayloadTonWhalesPoolDepositRaw = z.infer<
190+
typeof schemaTonPayloadTonWhalesPoolDepositRaw
191+
>;
192+
193+
export type TonPayloadTonWhalesPoolWithdraw = {
194+
type: "tonwhales-pool-withdraw";
195+
queryId: bigint;
196+
gasLimit: bigint;
197+
amount: bigint;
198+
};
199+
200+
export type TonPayloadTonWhalesPoolWithdrawRaw = z.infer<
201+
typeof schemaTonPayloadTonWhalesPoolWithdrawRaw
202+
>;
203+
204+
export type TonPayloadVestingSendMsgComment = {
205+
type: "vesting-send-msg-comment";
206+
queryId: bigint | null;
207+
sendMode: number;
208+
value: bigint;
209+
destination: Address;
210+
text: string;
211+
};
212+
213+
export type TonPayloadVestingSendMsgCommentRaw = z.infer<
214+
typeof schemaTonPayloadVestingSendMsgCommentRaw
215+
>;
216+
180217
export type TonPayloadFormat =
181218
| TonPayloadComment
182219
| TonPayloadJettonTransfer
@@ -189,6 +226,9 @@ export type TonPayloadFormat =
189226
| TonPayloadTonStakersDeposit
190227
| TonPayloadVoteForProposal
191228
| TonPayloadChangeDnsRecord
192-
| TonPayloadTokenBridgePaySwap;
229+
| TonPayloadTokenBridgePaySwap
230+
| TonPayloadTonWhalesPoolDeposit
231+
| TonPayloadTonWhalesPoolWithdraw
232+
| TonPayloadVestingSendMsgComment;
193233

194234
export type TonPayloadFormatRaw = z.infer<typeof schemaTonPayloadFormatRaw>;

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,28 @@ export const schemaTonPayloadTokenBridgePaySwapRaw = z.object({
118118
swapId: z.string(),
119119
});
120120

121+
export const schemaTonPayloadTonWhalesPoolDepositRaw = z.object({
122+
type: z.literal("tonwhales-pool-deposit"),
123+
queryId: z.string(),
124+
gasLimit: z.string(),
125+
});
126+
127+
export const schemaTonPayloadTonWhalesPoolWithdrawRaw = z.object({
128+
type: z.literal("tonwhales-pool-withdraw"),
129+
queryId: z.string(),
130+
gasLimit: z.string(),
131+
amount: z.string(),
132+
});
133+
134+
export const schemaTonPayloadVestingSendMsgCommentRaw = z.object({
135+
type: z.literal("vesting-send-msg-comment"),
136+
queryId: z.union([z.string(), z.null()]),
137+
sendMode: z.number(),
138+
value: z.string(),
139+
destination: z.string(),
140+
text: z.string(),
141+
});
142+
121143
export const schemaTonPayloadFormatRaw = z.union([
122144
schemaTonPayloadCommentRaw,
123145
schemaTonPayloadJettonTransferRaw,
@@ -131,6 +153,9 @@ export const schemaTonPayloadFormatRaw = z.union([
131153
schemaTonPayloadVoteForProposalRaw,
132154
schemaTonPayloadChangeDnsRecordRaw,
133155
schemaTonPayloadTokenBridgePaySwapRaw,
156+
schemaTonPayloadTonWhalesPoolDepositRaw,
157+
schemaTonPayloadTonWhalesPoolWithdrawRaw,
158+
schemaTonPayloadVestingSendMsgCommentRaw,
134159
]);
135160

136161
export const schemaRawTonTransaction = schemaTransactionCommon.extend({

packages/core/tests/ton-serializers.spec.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,71 @@ const cases: {
406406
},
407407
},
408408
},
409+
{
410+
name: "tx with payload for tonwhales-pool-deposit",
411+
tx: {
412+
...baseTx,
413+
payload: {
414+
type: "tonwhales-pool-deposit",
415+
queryId: BigInt(1),
416+
gasLimit: BigInt(1000000),
417+
},
418+
},
419+
rawTx: {
420+
...baseRawTx,
421+
payload: {
422+
type: "tonwhales-pool-deposit",
423+
queryId: "1",
424+
gasLimit: "1000000",
425+
},
426+
},
427+
},
428+
{
429+
name: "tx with payload for tonwhales-pool-withdraw",
430+
tx: {
431+
...baseTx,
432+
payload: {
433+
type: "tonwhales-pool-withdraw",
434+
queryId: BigInt(2),
435+
gasLimit: BigInt(2000000),
436+
amount: BigInt(5000000000),
437+
},
438+
},
439+
rawTx: {
440+
...baseRawTx,
441+
payload: {
442+
type: "tonwhales-pool-withdraw",
443+
queryId: "2",
444+
gasLimit: "2000000",
445+
amount: "5000000000",
446+
},
447+
},
448+
},
449+
{
450+
name: "tx with payload for vesting-send-msg-comment",
451+
tx: {
452+
...baseTx,
453+
payload: {
454+
type: "vesting-send-msg-comment",
455+
queryId: BigInt(3),
456+
sendMode: 3,
457+
value: BigInt(42),
458+
destination: randomAddress,
459+
text: "vesting comment",
460+
},
461+
},
462+
rawTx: {
463+
...baseRawTx,
464+
payload: {
465+
type: "vesting-send-msg-comment",
466+
queryId: "3",
467+
sendMode: 3,
468+
value: "42",
469+
destination: rawRandomAddress,
470+
text: "vesting comment",
471+
},
472+
},
473+
},
409474
{
410475
name: "tx with payload we don't support",
411476
tx: {

0 commit comments

Comments
 (0)