@ton-agent-kit/plugin-escrow 1.0.3 → 1.1.0

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.
@@ -0,0 +1,50 @@
1
+ import { z } from "zod";
2
+ import { Address } from "@ton/core";
3
+ import { defineAction, toFriendlyAddress } from "@ton-agent-kit/core";
4
+ import { loadEscrows, saveEscrows, voteRefundOnContract, getLatestTxHash } from "../utils";
5
+
6
+ export const voteRefundAction = defineAction({
7
+ name: "vote_refund",
8
+ description:
9
+ "Vote to refund escrow funds to the depositor during a multi-arbiter dispute. Must be called by a registered arbiter. When majority is reached, funds are automatically refunded.",
10
+ schema: z.object({
11
+ escrowId: z.string().describe("Escrow ID to vote refund on"),
12
+ }),
13
+ handler: async (agent, params) => {
14
+ const escrows = loadEscrows();
15
+ const escrow = escrows[params.escrowId];
16
+ if (!escrow) {
17
+ return { voted: false, message: `Escrow not found: ${params.escrowId}` };
18
+ }
19
+
20
+ const contractAddress = Address.parse(escrow.contractAddress);
21
+
22
+ try {
23
+ await voteRefundOnContract(agent, contractAddress);
24
+
25
+ const txHash = await getLatestTxHash(
26
+ agent.wallet.address.toRawString(),
27
+ agent.network,
28
+ );
29
+
30
+ return {
31
+ voted: true,
32
+ vote: "refund",
33
+ escrowId: params.escrowId,
34
+ contractAddress: escrow.contractAddress,
35
+ friendlyContract: toFriendlyAddress(contractAddress, agent.network),
36
+ voter: agent.wallet.address.toRawString(),
37
+ voteTxHash: txHash,
38
+ message: `Voted to refund escrow ${params.escrowId}. Contract will auto-execute when majority is reached.`,
39
+ };
40
+ } catch (err: any) {
41
+ return {
42
+ voted: false,
43
+ vote: "refund",
44
+ escrowId: params.escrowId,
45
+ error: err.message,
46
+ message: `Vote failed: ${err.message}`,
47
+ };
48
+ }
49
+ },
50
+ });
@@ -0,0 +1,50 @@
1
+ import { z } from "zod";
2
+ import { Address } from "@ton/core";
3
+ import { defineAction, toFriendlyAddress } from "@ton-agent-kit/core";
4
+ import { loadEscrows, saveEscrows, voteReleaseOnContract, getLatestTxHash } from "../utils";
5
+
6
+ export const voteReleaseAction = defineAction({
7
+ name: "vote_release",
8
+ description:
9
+ "Vote to release escrow funds to the beneficiary during a multi-arbiter dispute. Must be called by a registered arbiter. When majority is reached, funds are automatically released.",
10
+ schema: z.object({
11
+ escrowId: z.string().describe("Escrow ID to vote release on"),
12
+ }),
13
+ handler: async (agent, params) => {
14
+ const escrows = loadEscrows();
15
+ const escrow = escrows[params.escrowId];
16
+ if (!escrow) {
17
+ return { voted: false, message: `Escrow not found: ${params.escrowId}` };
18
+ }
19
+
20
+ const contractAddress = Address.parse(escrow.contractAddress);
21
+
22
+ try {
23
+ await voteReleaseOnContract(agent, contractAddress);
24
+
25
+ const txHash = await getLatestTxHash(
26
+ agent.wallet.address.toRawString(),
27
+ agent.network,
28
+ );
29
+
30
+ return {
31
+ voted: true,
32
+ vote: "release",
33
+ escrowId: params.escrowId,
34
+ contractAddress: escrow.contractAddress,
35
+ friendlyContract: toFriendlyAddress(contractAddress, agent.network),
36
+ voter: agent.wallet.address.toRawString(),
37
+ voteTxHash: txHash,
38
+ message: `Voted to release escrow ${params.escrowId}. Contract will auto-execute when majority is reached.`,
39
+ };
40
+ } catch (err: any) {
41
+ return {
42
+ voted: false,
43
+ vote: "release",
44
+ escrowId: params.escrowId,
45
+ error: err.message,
46
+ message: `Vote failed: ${err.message}`,
47
+ };
48
+ }
49
+ },
50
+ });