@ton-agent-kit/plugin-escrow 1.2.0 → 1.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ton-agent-kit/plugin-escrow",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Escrow plugin for TON Agent Kit — create, fund, release, and refund escrow deals",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -1717,6 +1717,7 @@ export type Escrow$Data = {
1717
1717
  baseSellerStake: bigint;
1718
1718
  requireRepCollateral: boolean;
1719
1719
  minRepScore: bigint;
1720
+ totalArbiterStakes: bigint;
1720
1721
  }
1721
1722
 
1722
1723
  export function storeEscrow$Data(src: Escrow$Data) {
@@ -1750,6 +1751,7 @@ export function storeEscrow$Data(src: Escrow$Data) {
1750
1751
  b_2.storeCoins(src.baseSellerStake);
1751
1752
  b_2.storeBit(src.requireRepCollateral);
1752
1753
  b_2.storeUint(src.minRepScore, 8);
1754
+ b_2.storeCoins(src.totalArbiterStakes);
1753
1755
  b_1.storeRef(b_2.endCell());
1754
1756
  b_0.storeRef(b_1.endCell());
1755
1757
  };
@@ -1785,7 +1787,8 @@ export function loadEscrow$Data(slice: Slice) {
1785
1787
  const _baseSellerStake = sc_2.loadCoins();
1786
1788
  const _requireRepCollateral = sc_2.loadBit();
1787
1789
  const _minRepScore = sc_2.loadUintBig(8);
1788
- return { $$type: 'Escrow$Data' as const, depositor: _depositor, beneficiary: _beneficiary, reputationContract: _reputationContract, amount: _amount, deadline: _deadline, released: _released, refunded: _refunded, deliveryConfirmed: _deliveryConfirmed, disputed: _disputed, votingDeadline: _votingDeadline, minArbiters: _minArbiters, minStake: _minStake, arbiters: _arbiters, arbiterIndex: _arbiterIndex, stakes: _stakes, voted: _voted, votes: _votes, arbiterCount: _arbiterCount, votesRelease: _votesRelease, votesRefund: _votesRefund, sellerStake: _sellerStake, sellerStaked: _sellerStaked, requireSellerStake: _requireSellerStake, baseSellerStake: _baseSellerStake, requireRepCollateral: _requireRepCollateral, minRepScore: _minRepScore };
1790
+ const _totalArbiterStakes = sc_2.loadCoins();
1791
+ return { $$type: 'Escrow$Data' as const, depositor: _depositor, beneficiary: _beneficiary, reputationContract: _reputationContract, amount: _amount, deadline: _deadline, released: _released, refunded: _refunded, deliveryConfirmed: _deliveryConfirmed, disputed: _disputed, votingDeadline: _votingDeadline, minArbiters: _minArbiters, minStake: _minStake, arbiters: _arbiters, arbiterIndex: _arbiterIndex, stakes: _stakes, voted: _voted, votes: _votes, arbiterCount: _arbiterCount, votesRelease: _votesRelease, votesRefund: _votesRefund, sellerStake: _sellerStake, sellerStaked: _sellerStaked, requireSellerStake: _requireSellerStake, baseSellerStake: _baseSellerStake, requireRepCollateral: _requireRepCollateral, minRepScore: _minRepScore, totalArbiterStakes: _totalArbiterStakes };
1789
1792
  }
1790
1793
 
1791
1794
  export function loadTupleEscrow$Data(source: TupleReader) {
@@ -1816,7 +1819,8 @@ export function loadTupleEscrow$Data(source: TupleReader) {
1816
1819
  const _baseSellerStake = source.readBigNumber();
1817
1820
  const _requireRepCollateral = source.readBoolean();
1818
1821
  const _minRepScore = source.readBigNumber();
1819
- return { $$type: 'Escrow$Data' as const, depositor: _depositor, beneficiary: _beneficiary, reputationContract: _reputationContract, amount: _amount, deadline: _deadline, released: _released, refunded: _refunded, deliveryConfirmed: _deliveryConfirmed, disputed: _disputed, votingDeadline: _votingDeadline, minArbiters: _minArbiters, minStake: _minStake, arbiters: _arbiters, arbiterIndex: _arbiterIndex, stakes: _stakes, voted: _voted, votes: _votes, arbiterCount: _arbiterCount, votesRelease: _votesRelease, votesRefund: _votesRefund, sellerStake: _sellerStake, sellerStaked: _sellerStaked, requireSellerStake: _requireSellerStake, baseSellerStake: _baseSellerStake, requireRepCollateral: _requireRepCollateral, minRepScore: _minRepScore };
1822
+ const _totalArbiterStakes = source.readBigNumber();
1823
+ return { $$type: 'Escrow$Data' as const, depositor: _depositor, beneficiary: _beneficiary, reputationContract: _reputationContract, amount: _amount, deadline: _deadline, released: _released, refunded: _refunded, deliveryConfirmed: _deliveryConfirmed, disputed: _disputed, votingDeadline: _votingDeadline, minArbiters: _minArbiters, minStake: _minStake, arbiters: _arbiters, arbiterIndex: _arbiterIndex, stakes: _stakes, voted: _voted, votes: _votes, arbiterCount: _arbiterCount, votesRelease: _votesRelease, votesRefund: _votesRefund, sellerStake: _sellerStake, sellerStaked: _sellerStaked, requireSellerStake: _requireSellerStake, baseSellerStake: _baseSellerStake, requireRepCollateral: _requireRepCollateral, minRepScore: _minRepScore, totalArbiterStakes: _totalArbiterStakes };
1820
1824
  }
1821
1825
 
1822
1826
  export function loadGetterTupleEscrow$Data(source: TupleReader) {
@@ -1846,7 +1850,8 @@ export function loadGetterTupleEscrow$Data(source: TupleReader) {
1846
1850
  const _baseSellerStake = source.readBigNumber();
1847
1851
  const _requireRepCollateral = source.readBoolean();
1848
1852
  const _minRepScore = source.readBigNumber();
1849
- return { $$type: 'Escrow$Data' as const, depositor: _depositor, beneficiary: _beneficiary, reputationContract: _reputationContract, amount: _amount, deadline: _deadline, released: _released, refunded: _refunded, deliveryConfirmed: _deliveryConfirmed, disputed: _disputed, votingDeadline: _votingDeadline, minArbiters: _minArbiters, minStake: _minStake, arbiters: _arbiters, arbiterIndex: _arbiterIndex, stakes: _stakes, voted: _voted, votes: _votes, arbiterCount: _arbiterCount, votesRelease: _votesRelease, votesRefund: _votesRefund, sellerStake: _sellerStake, sellerStaked: _sellerStaked, requireSellerStake: _requireSellerStake, baseSellerStake: _baseSellerStake, requireRepCollateral: _requireRepCollateral, minRepScore: _minRepScore };
1853
+ const _totalArbiterStakes = source.readBigNumber();
1854
+ return { $$type: 'Escrow$Data' as const, depositor: _depositor, beneficiary: _beneficiary, reputationContract: _reputationContract, amount: _amount, deadline: _deadline, released: _released, refunded: _refunded, deliveryConfirmed: _deliveryConfirmed, disputed: _disputed, votingDeadline: _votingDeadline, minArbiters: _minArbiters, minStake: _minStake, arbiters: _arbiters, arbiterIndex: _arbiterIndex, stakes: _stakes, voted: _voted, votes: _votes, arbiterCount: _arbiterCount, votesRelease: _votesRelease, votesRefund: _votesRefund, sellerStake: _sellerStake, sellerStaked: _sellerStaked, requireSellerStake: _requireSellerStake, baseSellerStake: _baseSellerStake, requireRepCollateral: _requireRepCollateral, minRepScore: _minRepScore, totalArbiterStakes: _totalArbiterStakes };
1850
1855
  }
1851
1856
 
1852
1857
  export function storeTupleEscrow$Data(source: Escrow$Data) {
@@ -1877,6 +1882,7 @@ export function storeTupleEscrow$Data(source: Escrow$Data) {
1877
1882
  builder.writeNumber(source.baseSellerStake);
1878
1883
  builder.writeBoolean(source.requireRepCollateral);
1879
1884
  builder.writeNumber(source.minRepScore);
1885
+ builder.writeNumber(source.totalArbiterStakes);
1880
1886
  return builder.build();
1881
1887
  }
1882
1888
 
@@ -1924,7 +1930,7 @@ function initEscrow_init_args(src: Escrow_init_args) {
1924
1930
  }
1925
1931
 
1926
1932
  async function Escrow_init(depositor: Address, beneficiary: Address, deadline: bigint, minArbiters: bigint, minStake: bigint, reputationContract: Address, requireRepCollateral: boolean, minRepScore: bigint, baseSellerStake: bigint) {
1927
- const __code = Cell.fromHex('b5ee9c724102480100147000022cff008e88f4a413f4bcf2c80bed53208e8130e1ed43d90107020378e002040325b96c0ed44d0d20001e30fdb3c57105f0f6ca18080a030008f8276f1003d5bbed2ed44d0d20001e30fdb3c571757175717571757175717571757175717571757175717571757175717571757175717571757175717571757175717571757171113111611131112111511121111111411111110111311100f11120f0e11110e0d11100d10cf10be552a8080a0501f4f8235616be9256129170e2935614b39170e2935613b39170e2935611b39170e2f8235617be935613b39170e2935615b39170e2935614b39170e2935612b39170e2561b02561b02561b02561b02561b02561b02561b02561b02561b02561b02561402561402561402561e02561e0256160256160256160256160206000c561602561659048201d072d721d200d200fa4021103450666f04f86102f862ed44d0d20001e30f111b945f0f5f0ce01119d70d1ff2e082218210f19f83efbae302218210f8aa2f92ba080a0b0d01f6fa40fa40fa40fa00d31fd200d200d200d200d31fd307d401d0fa00f404f404f404d430d0f404f404d30fd30fd30ffa00d200d200fa00d200d307300f111a0f0f11190f0f11180f0f11170f0f11160f0f11150f0f11140f0f11130f0f11120f0f11110f0f11100f571a1118111911181117111811171116111711160900541115111611151114111511141113111411131112111311121111111211111110111111100f11100f550e00f4fa40fa40810101d700d401d0810101d700810101d700fa40d200d430d0810101d700810101d7003010691068106709d155076d6d6d6d6d707070707054744453007056121114111711140b11160b1114111511140a11140a0911130908111208071111070611100610bf10ae106d10bc10ab106a10691058552401fe5b33815c50f8425617c705f2f48116595612b3935611b39170e2f2f420f2e78d8200e85002b312f2f48200c718f8416f24135f03c200f2f4f8416f24135f031116111811161115111711151114111611141113111511131112111411121111111311111110111211100f11110f0e11100e10df10ce10bd10ac109b108a10790c011c1068105710461035047f4344db3c4604fa8ee55b21978200f23123f2f4def8416f24135f0301111501a011171119111711161118111611151117111511161113111511131112111411121111111311111110111211100f11110f0e11100e10df10ce10bd10ac109b108a107910681057104610354403db3ce0218210d2d77e02bae3022182101856d189bae30221460e111402f65b5710820097dbf8425618c705f2f48116595612b3935611b39170e2f2f47ff842708042708810246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb001117111911171116111811161115111711151114111611141113111511130f10002c0000000044656c697665727920636f6e6669726d6564016011121114111211111113111111120f11110f0e11100e10df10ce10bd10ac109b108a107910681057104610354403db3c4602fe5b8116591113b3935611b39170e201111301f2f48164272fb3f2f48200af75f8425618c705f2f48200a1c75614c200f2f47f708100827088561a553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb001117111911171116111811161213002600000000457363726f772072656c6561736564018411151117111511141116111411131115111311141111111311111110111211100f11110f0e11100e10df10ce10bd10ac109b108a107910681057104610354403db3c46044a821083fb1615bae302218210464d5ef3bae3022182109ec0cde6bae302218210c28a4884ba15181b1f02fe5b8116595613b3931112b393571270e201111201f2f48164272fb3f2f48200a1c75614c200f2f4f8235613b99c8200f74df8425618c705f2f4982f95812a05f2f0dee27f708100827088561b553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e21617002600000000457363726f7720726566756e64656401aaf400c901fb0011171119111711161118111611151117111511141116111411131115111311121114111211131110111211100f11110f0e11100e10df10ce10bd10ac109b108a10791068105710461035443012db3c4602fc5b8200bc49f8235615bef2f48200cc285611f2f48116591113b3935611b39170e201111301f2f42eb3f2e4a18200a1c75614c200f2f47f708100827088561a553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb00111711191117191a0040000000004175746f2d72656c656173656420616674657220646561646c696e65019011161118111611151117111511141116111411131115111311141111111311111110111211100f11110f0e11100e10df10ce10bd10ac109b108a107910681057104610354403db3c4601fe5b3e8200e28cf8425618c705917f96f8425617c705e2f2f48116595612b3935611b39170e2f2f48200ae570fb31ff2f47ff8238203f480a08209c9c380727ff828561b561b561a27c8554082102f7e50595006cb1f14ce12cece01fa02cb1fc95619553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e1c02fc016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb00f842708042708810246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb001117111911171116111811161115111711151114111611141113111511131112111411121d1e00240000000044697370757465206f70656e6564015811111113111111101112111001111101111010df10ce10bd10ac109b108a107910681057104610354400db3c4602fc8efa5b81575a5610f2f48116595613b3935612b39170e2f2f4813c8df8235610b9f2f4810f8927c164f2f4813ce7f8425619c705b3f2f482009100f8425618c705b3f2f481010bf8422c598101014133f40a6fa19401d70030925b6de281654b016ef2f4f8416f24135f038126e7531ebef2f4810101f84229103f01e021202201f6206e953059f45a30944133f414e281010bf84229103e810101216e955b59f4593098c801cf004133f441e281010120103c54491350ff216e955b59f45a3098c801cf004133f442e208810101277071216e955b59f45a3098c801cf004133f442e206a411171119111711161118111611151117111511141116111421016c1113111511131112111411121111111311111110111211100f11110f0e11100e10df10ce5e2a108b5e3608105710461035440302db3c4602fe820aaade5bba8ef75b81575a5610f2f48116595613b3935612b39170e2f2f48153fa537ebef2f481010bf8422c598101014133f40a6fa19401d70030925b6de2814a09216eb3f2f4206ef2d0802981010122714133f40c6fa19401d70030925b6de2812583216eb3f2f48200e7e901206ef2d080c000f2f4098101012a7f71232a0372216e955b59f45a3098c801cf004133f442e218810101500a7f71216e955b59f45a3098c801cf004133f442e205a426ab00a45210bee30fdb3c24274604fe57121116111811161115111711151114111611141113111511131112111411127f11141111111311111110111211100f11110f0e11100e10df10ce10bd10ac109b108a5e351067104610354403db3c708100827088561c553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf818ae2f4003f253b2600380000000052656c6561736564206279206172626974657220766f74650008c901fb0002fcf842708042708810246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb001117111911171116111811161115111711151114111611141113111511131112111411121111111311111110111211100f11110f0e11100e10df10ce10bd10ac2829002800000000566f74656420746f2072656c656173650012109b108a5e35075514044ee02182104cbc6df3bae30221821080432205bae302218210dcaf1044bae302018210946a98b6ba2b333d4401ee5b81575a5610f2f48116595613b3935612b39170e2f2f48153fa537ebef2f481010bf8422c598101014133f40a6fa19401d70030925b6de2814a09216eb3f2f4206ef2d0802981010122714133f40c6fa19401d70030925b6de2812583216eb3f2f48200e7e901206ef2d080c000f2f4098101012a7f712c0372216e955b59f45a3098c801cf004133f442e218810101500a7071216e955b59f45a3098c801cf004133f442e204a426ab00a45210bee30fdb3c2d304604fe57111116111811161115111711151114111611141113111511131112111411121111111311117f11131110111211100f11110f0e11100e10df10ce10bd10ac109b108a10491068105710461035443012db3c708100827088561d553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf818a3f2e3b2f003800000000526566756e646564206279206172626974657220766f7465000ee2f400c901fb0002fcf842708042708810246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb001117111911171116111811161115111711151114111611141113111511131112111411121111111311111110111211100f11110f0e11100e10df10ce10bd10ac3132002600000000566f74656420746f20726566756e640020109b108a10491068105706103544030201f85b8168575613917f925612e2f2f481010bf8422c598101014133f40a6fa19401d70030925b6de2814a09216eb3f2f4206ef2d080810101545b0052304133f40c6fa19401d70030925b6de2812583216eb3f2f482009d7321206ef2d080c200f2f42a81010123714133f40c6fa19401d70030925b6de28174c1216eb33402fe9801206ef2d080c0ff923170e2f2f42981010123714133f40c6fa19401d70030925b6de2206ef2d08020c0ff9256159170e292307f98c0009256139170e2e28101017021104f10231025216e955b59f45a3098c801cf004133f442e201913ae30d111711191117111611181116111511171115111411161114111311151113353c02fc1118111911181117111811171116111711161115111611151114111511141113111411131112111311121111111211111110111111100f11100f10ef10de10cd0b0c5509111adb3c1119111a11191118111a11181117111a11171116111a11161115111a11151114111a11141113111a11131112111a11121111111a1111363801f6702093530ab98e732b81010122714133f40c6fa19401d70030925b6de2206eb38e5520206ef2d080c0ff9256179170e292307f9d206ef2d080c0009256159170e2e28e32810101545e0052304133f40c6fa19401d70030925b6de2206eb39820206ef2d080c2009170e298206ef2d08012a0019130e2df9130e2a4370004e83003f41110111a11100f111a0f0e111a0e0d111a0d0c111a0c0b111a0b0a111a0a09111a09111a0807065540db3c7021c200993001111b01a904111a93571c30e2111b206ef2d08001111aa0f842727088103410246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf818ae2f400c901fb00393a3b00ec702093530ab98e6c2b81010122714133f40c6fa19401d70030925b6de2206eb38e4e20206ef2d080c0ff9256179170e292307f9d206ef2d080c0009256159170e2e28e2b810101545e0052304133f40c6fa19401d70030925b6de2206eb397206ef2d080c200923070e29301a401dede9130e2a4e8300036000000004172626974657220726577617264202877696e6e657229001a58cf8680cf8480f400f400cf8101401112111411121111111311111110111211100f11110f0e11100e10df551cdb3c4601fc5b81575a5610f2f48116595613b3935612b39170e2f2f48200d92bf8235610bef2f4536db9917f935354bae28e1356109357127f9b57111110111111107f1111e28e145354bc9357127f9b57111110111111107f1111e2e211171119111711161118111611151117111511141116111411131115111311141111111311113e04de1110111211100f11110f0e11100e10df10ce10bd10ac109b108a107910681057104610354403db3c56148ec1708100827088561d553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb00e30d3f40414300c256118e5c8209312d00727ff82856185618c855208210bfa059865004cb1f12ceca00ca00c9561b553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb00de002c0000000046616c6c6261636b3a20726566756e6465640182708100827088561c553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb0042002c0000000046616c6c6261636b3a2072656c65617365640104db3c4601e48ee8d33f30c8018210aff90f5758cb1fcb3fc91118111a11181117111911171116111811161115111711151114111611141113111511131112111411121111111311111110111211100f11110f0e11100e10df10ce10bd10ac109b108a10791068105710461035443012e05f0f5f0cf2c08245014af84270705003804201503304c8cf8580ca00cf8440ce01fa02806acf40f400c901fb00db3c46013ac87f01ca00111a111911181117111611151114111311121111111055e04700ca01111901111ace01111701ce01111501ce011113fa0201111101cb1f1fca001dca001bca0019ca0017cb1f15cb07c85004fa0212f400f40012f40002c8f40013f40013cb0f13cb0f13cb0f5003fa0213ca0013ca005003fa0213ca0013cb0712cdcdc9ed54b323604e');
1933
+ const __code = Cell.fromHex('b5ee9c7241024b0100164f00022cff008e88f4a413f4bcf2c80bed53208e8130e1ed43d90108020378e00204038db96c0ed44d0d200018eb2fa40fa40810101d700d401d0810101d700810101d700fa40d200d430d0810101d700810101d7003010691068106709d15507e30ddb3c57105f0f6cb18090a030008f8276f1004f9bbed2ed44d0d200018eb2fa40fa40810101d700d401d0810101d700810101d700fa40d200d430d0810101d700810101d7003010691068106709d15507e30ddb3c5717571757175717571757175717571757175717571757175717571757175717571757175717571757175717571757175717571757171112111611128090a050701f4f8235617be9256139170e2935615b39170e2935614b39170e2935612b39170e2f8235618be935614b39170e2935616b39170e2935615b39170e2935613b39170e2561c02561c02561c02561c02561c02561c02561c02561c02561c02561c02561502561502561502561f02561f0256170256170256170256170206000c56170256175900401111111511111110111411100f11130f0e11120e0d11110d0c11100c10bf553a04ea01d072d721d200d200fa4021103450666f04f86102f862ed44d0d200018eb2fa40fa40810101d700d401d0810101d700810101d700fa40d200d430d0810101d700810101d7003010691068106709d15507e30d111c945f0f5f0de0111ad70d1ff2e082218210f19f83efbae302218210f8aa2f92ba090a0d0f00a66d6d6d6d6d70707070705474445300705612221115111811150c11170c1115111611150b11150b0a11140a0911130908111208071111070c11100c10bf107e10cd10bc107b107a106910581047103645404130018cdb3c571b1119111a11191118111911181117111811171116111711161115111611151114111511141113111411131112111311121111111211111110111111100f11100f550e0b01f2fa40fa40fa40fa00d31fd200d200d200d200d31fd307d401d0fa00f404f404f404d430d0f404f404d30fd30fd30ffa00d200d200fa00d200d307fa00301110111b11101110111a11101110111911101110111811101110111711101110111611101110111511101110111411101110111311101110111211100c000c11101111111003fe5b34815c50f8425618c705f2f48116595613b3935612b39170e2f2f421f2e78d8200e85003b313f2f48200c718f8416f24135f03c200f2f4f8416f24135f037f561522a0561ba08208989680a070fb02f84270810082708810246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf818ae2f400c93e280e01ae01fb001118111a11181117111911171116111811161115111711151114111611141113111511131112111411121111111311111110111211100f11110f0e11100e10df10ce10bd10ac109b108a1079106805446701db3c4903f48eec5b22978200f23124f2f4def8416f24135f0301111601a01118111a111811171119111711161118111611171114111611141113111511131112111411121111111311111110111211100f11110f0e11100e10df10ce10bd10ac109b108a10791068105710461035440302db3ce0218210d2d77e02bae3022149101202f45b5711820097dbf8425619c705f2f48116595613b3935612b39170e2f2f47f561525a0561ba08208989680a070fb02f84270810082708810246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb001118111a11181117111911173e11019211161118111611151117111511141116111411131115111311121114111211131110111211100f11110f0e11100e10df10ce10bd10ac109b108a10791068105710461035440302db3c49044a82101856d189bae30221821083fb1615bae302218210464d5ef3bae3022182109ec0cde6ba1315181b02f45b8116591114b3935612b39170e201111401f2f48164275610b3f2f48200af75f8425619c705f2f48200a1c75615c200f2f47f708100827088561b553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb001118111a1118141a002600000000457363726f772072656c656173656403f45b8116595614b3931113b393571370e201111301f2f48164275610b3f2f48200a1c75615c200f2f4f8235614b99c8200f74df8425619c705f2f499561095812a05f2f0dee27f708100827088561c553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf818ae2f400c901fb00162817002600000000457363726f7720726566756e64656401a81118111a111811171119111711161118111611151117111511141116111411131115111311141111111311111110111211100f11110f0e11100e10df10ce10bd10ac109b108a107910681057104610354430db3c4902fc5b8200bc49f8235616bef2f48200cc285612f2f48116591114b3935612b39170e201111401f2f42fb3f2e4a18200a1c75615c200f2f47f708100827088561b553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb001118111a1118191a0040000000004175746f2d72656c656173656420616674657220646561646c696e65019e11171119111711161118111611151117111511141116111411151112111411121111111311111110111211100f11110f0e11100e10df10ce10bd10ac109b108a10791068105710461035440302db3c49043ae302218210c28a4884bae30221820aaade5bbae3022182104cbc6df3ba1c1f232b01fc5b3f8200e28cf8425619c705917f96f8425618c705e2f2f48116595613b3935612b39170e2f2f48200ae571110b301111001f2f47ff8238203f480a08209c9c380727ff828561c561c561b27c8554082102f7e50595006cb1f14ce12cece01fa02cb1fc9561a553010246d50436d03c8cf8580ca00cf8440ce01fa0280691d02f8cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb00561525a0561ba08208989680a070fb02f84270810082708810246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb001118111a11181117111911173e1e01941116111811161115111711151114111611141113111511131112111411121111111311110111120111110e11100e10df10ce10bd10ac109b108a1079106810571046103510244300db3c4901f45b81575a5611f2f48116595614b3935613b39170e2f2f4813c8df8235611b9f2f4810f8928c164f2f4813ce7f842561ac705b3f2f482009100f8425619c705b3f2f481010bf8422d598101014133f40a6fa19401d70030925b6de281654b016ef2f4f8416f24135f038126e7531fbef2f4810101f842102f52a02001fe206e953059f45a30944133f414e281010bf8422a103f810101216e955b59f4593098c801cf004133f441e2810101541c0052a0561001216e955b59f45a3098c801cf004133f442e20a810101297071216e955b59f45a3098c801cf004133f442e208a401111b010da0561525a021a08208989680a070fb02f84270810082702102fc8810246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb001118111a11181117111911171116111811161115111711151114111611141113111511131112111411121111111311111110111211100f11110f0e11100e10df10be10ad109c3e22011e5e371068105710461035443012db3c4901ee5b81575a5611f2f48116595614b3935613b39170e2f2f48153fa538fbef2f481010bf8422d598101014133f40a6fa19401d70030925b6de2814a09216eb3f2f4206ef2d0802a81010122714133f40c6fa19401d70030925b6de2812583216eb3f2f48200e7e901206ef2d080c000f2f40a8101012b7f71240372216e955b59f45a3098c801cf004133f442e219810101500b7f71216e955b59f45a3098c801cf004133f442e206a427ab00a45210bee30fdb3c25294904fe57131117111911171116111811161115111711151114111611141113111511137f11151112111411121111111311111110111211100f11110f0e11100e10df10ce10bd10ac109b5e361078105710461035440302db3c708100827088561d553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb08a4226302700380000000052656c6561736564206279206172626974657220766f746501108ae2f400c901fb0028001a58cf8680cf8480f400f400cf8102fe561525a0561ba08208989680a070fb02f84270810082708810246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb001118111a11181117111911171116111811161115111711151114111611141113111511131112111411121111111311113e2a003a1110111211100f11110f0e11100e10df10ce10bd10ac109b5e3608551502f68ef75b81575a5611f2f48116595614b3935613b39170e2f2f48153fa538fbef2f481010bf8422d598101014133f40a6fa19401d70030925b6de2814a09216eb3f2f4206ef2d0802a81010122714133f40c6fa19401d70030925b6de2812583216eb3f2f48200e7e901206ef2d080c000f2f40a8101012b7f71e0212c330372216e955b59f45a3098c801cf004133f442e219810101500b7071216e955b59f45a3098c801cf004133f442e205a427ab00a45210bee30fdb3c2d314903fe57121117111911171116111811161115111711151114111611141113111511131112111411127f11141111111311111110111211100f11110f0e11100e10df10ce10bd10ac109b105a107910681057104610354430db3c708100827088561e553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0422e2f003800000000526566756e646564206279206172626974657220766f7465012c8a9d58cf8680cf8480f400f400cf81e2f400c901fb003000065bcf8102fe561525a0561ba08208989680a070fb02f84270810082708810246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb001118111a11181117111911171116111811161115111711151114111611141113111511131112111411121111111311113e32004a1110111211100f11110f0e11100e10df10ce10bd10ac109b105a10791068071046103544030348821080432205bae302218210dcaf1044bae302018210946a98b6bae3025f0f5f0df2c08234404701f85b8168575614917f925613e2f2f481010bf8422d598101014133f40a6fa19401d70030925b6de2814a09216eb3f2f4206ef2d080810101545c0052304133f40c6fa19401d70030925b6de2812583216eb3f2f482009d7321206ef2d080c200f2f42b81010123714133f40c6fa19401d70030925b6de28174c1216eb33502fc9801206ef2d080c0ff923170e2f2f42a81010123714133f40c6fa19401d70030925b6de2206ef2d08020c0ff9256169170e292307f98c0009256149170e2e221206ef2d08001111e01a181010170210411100410231025216e955b59f45a3098c801cf004133f442e2111c913be30d561525a02ba08208989680a070fb02363d02f41119111a11191118111911181117111811171116111711161115111611151114111511141113111411131112111311121111111211111110111111100f11100f10ef10de10cd0c111b0c10ab109a108910781067105610451034413001111b01db3c111a111b111a1119111b11191118111b11181117111b1117373901f6702093530bb98e732c81010122714133f40c6fa19401d70030925b6de2206eb38e5520206ef2d080c0ff9256189170e292307f9d206ef2d080c0009256169170e2e28e32810101545f0052304133f40c6fa19401d70030925b6de2206eb39820206ef2d080c2009170e298206ef2d08012a0019130e2df9130e2a4380004e83003fe1116111b11161115111b11151114111b11141113111b11131112111b11121111111b11111110111b11100f111b0f0e111b0e0d111b0d0c111b0c0b111b0b0a111b0a09111b09111b0807065540db3c7021c200993001111c01a904111b93571d30e2111c206ef2d08001111ba0f842727088103410246d50436d03c8cf85803a3b3c00ec702093530bb98e6c2c81010122714133f40c6fa19401d70030925b6de2206eb38e4e20206ef2d080c0ff9256189170e292307f9d206ef2d080c0009256169170e2e28e2b810101545f0052304133f40c6fa19401d70030925b6de2206eb397206ef2d080c200923070e29301a401dede9130e2a4e8300036000000004172626974657220726577617264202877696e6e6572290060ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb000a111a0a02fef84270810082708810246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb001118111a11181117111911171116111811161115111711151114111611141113111511131112111411121111111311111110111211100f11110f0e11100e10df3e3f001400000000457863657373011010ce10bd5519db3c4901fc5b81575a5611f2f48116595614b3935613b39170e2f2f48200d92bf8235611bef2f4537eb9917f935365bae28e1356119357137f9b57121111111211117f1112e28e145365bc9357137f9b57121111111211117f1112e2e21118111a111811171119111711161118111611151117111511141116111411151112111411124104ec1111111311111110111211100f11110f0e11100e10df10ce10bd10ac109b108a10791068105710461035440302db3c56158ec1708100827088561e553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb00e30d4243444600c256128e5c8209312d00727ff82856195619c855208210bfa059865004cb1f12ceca00ca00c9561c553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb00de002c0000000046616c6c6261636b3a20726566756e6465640182708100827088561d553010246d50436d03c8cf8580ca00cf8440ce01fa028069cf40025c6e016eb0935bcf819d58cf8680cf8480f400f400cf81e2f400c901fb0045002c0000000046616c6c6261636b3a2072656c65617365640104db3c4901dad33f30c8018210aff90f5758cb1fcb3fc91119111b11191118111a11181117111911171116111811161115111711151114111611141113111511131112111411121111111311111110111211100f11110f0e11100e10df10ce10bd10ac109b108a10791068105710461035443048014af84270705003804201503304c8cf8580ca00cf8440ce01fa02806acf40f400c901fb00db3c49013ec87f01ca00111b111a111911181117111611151114111311121111111055e04a00d401111a01111bce01111801ce01111601ce011114fa0201111201cb1f01111001ca001eca001cca001aca0018cb1f16cb07c85005fa0213f400f400f40002c8f40013f40013cb0f13cb0f13cb0f5003fa0213ca0013ca005003fa0213ca0013cb075003fa02cdcdc9ed542b895238');
1928
1934
  const builder = beginCell();
1929
1935
  builder.storeUint(0, 1);
1930
1936
  initEscrow_init_args({ $$type: 'Escrow_init_args', depositor, beneficiary, deadline, minArbiters, minStake, reputationContract, requireRepCollateral, minRepScore, baseSellerStake })(builder);
@@ -2105,7 +2111,7 @@ const Escrow_types: ABIType[] = [
2105
2111
  {"name":"NotifyDisputeOpened","header":796807257,"fields":[{"name":"escrowAddress","type":{"kind":"simple","type":"address","optional":false}},{"name":"depositor","type":{"kind":"simple","type":"address","optional":false}},{"name":"beneficiary","type":{"kind":"simple","type":"address","optional":false}},{"name":"amount","type":{"kind":"simple","type":"uint","optional":false,"format":"coins"}},{"name":"votingDeadline","type":{"kind":"simple","type":"uint","optional":false,"format":32}}]},
2106
2112
  {"name":"NotifyDisputeSettled","header":3214956934,"fields":[{"name":"escrowAddress","type":{"kind":"simple","type":"address","optional":false}},{"name":"released","type":{"kind":"simple","type":"bool","optional":false}},{"name":"refunded","type":{"kind":"simple","type":"bool","optional":false}}]},
2107
2113
  {"name":"EscrowData","header":null,"fields":[{"name":"depositor","type":{"kind":"simple","type":"address","optional":false}},{"name":"beneficiary","type":{"kind":"simple","type":"address","optional":false}},{"name":"reputationContract","type":{"kind":"simple","type":"address","optional":false}},{"name":"amount","type":{"kind":"simple","type":"uint","optional":false,"format":"coins"}},{"name":"deadline","type":{"kind":"simple","type":"uint","optional":false,"format":32}},{"name":"released","type":{"kind":"simple","type":"bool","optional":false}},{"name":"refunded","type":{"kind":"simple","type":"bool","optional":false}},{"name":"deliveryConfirmed","type":{"kind":"simple","type":"bool","optional":false}},{"name":"disputed","type":{"kind":"simple","type":"bool","optional":false}},{"name":"votingDeadline","type":{"kind":"simple","type":"uint","optional":false,"format":32}},{"name":"arbiterCount","type":{"kind":"simple","type":"uint","optional":false,"format":16}},{"name":"votesRelease","type":{"kind":"simple","type":"uint","optional":false,"format":16}},{"name":"votesRefund","type":{"kind":"simple","type":"uint","optional":false,"format":16}},{"name":"minArbiters","type":{"kind":"simple","type":"uint","optional":false,"format":8}},{"name":"minStake","type":{"kind":"simple","type":"uint","optional":false,"format":"coins"}},{"name":"sellerStake","type":{"kind":"simple","type":"uint","optional":false,"format":"coins"}},{"name":"sellerStaked","type":{"kind":"simple","type":"bool","optional":false}},{"name":"requireSellerStake","type":{"kind":"simple","type":"bool","optional":false}},{"name":"baseSellerStake","type":{"kind":"simple","type":"uint","optional":false,"format":"coins"}},{"name":"requireRepCollateral","type":{"kind":"simple","type":"bool","optional":false}},{"name":"minRepScore","type":{"kind":"simple","type":"uint","optional":false,"format":8}},{"name":"autoReleaseAvailable","type":{"kind":"simple","type":"bool","optional":false}},{"name":"refundAvailable","type":{"kind":"simple","type":"bool","optional":false}}]},
2108
- {"name":"Escrow$Data","header":null,"fields":[{"name":"depositor","type":{"kind":"simple","type":"address","optional":false}},{"name":"beneficiary","type":{"kind":"simple","type":"address","optional":false}},{"name":"reputationContract","type":{"kind":"simple","type":"address","optional":false}},{"name":"amount","type":{"kind":"simple","type":"uint","optional":false,"format":"coins"}},{"name":"deadline","type":{"kind":"simple","type":"uint","optional":false,"format":32}},{"name":"released","type":{"kind":"simple","type":"bool","optional":false}},{"name":"refunded","type":{"kind":"simple","type":"bool","optional":false}},{"name":"deliveryConfirmed","type":{"kind":"simple","type":"bool","optional":false}},{"name":"disputed","type":{"kind":"simple","type":"bool","optional":false}},{"name":"votingDeadline","type":{"kind":"simple","type":"uint","optional":false,"format":32}},{"name":"minArbiters","type":{"kind":"simple","type":"uint","optional":false,"format":8}},{"name":"minStake","type":{"kind":"simple","type":"uint","optional":false,"format":"coins"}},{"name":"arbiters","type":{"kind":"dict","key":"int","value":"address"}},{"name":"arbiterIndex","type":{"kind":"dict","key":"address","value":"int"}},{"name":"stakes","type":{"kind":"dict","key":"int","value":"int"}},{"name":"voted","type":{"kind":"dict","key":"int","value":"bool"}},{"name":"votes","type":{"kind":"dict","key":"int","value":"bool"}},{"name":"arbiterCount","type":{"kind":"simple","type":"uint","optional":false,"format":16}},{"name":"votesRelease","type":{"kind":"simple","type":"uint","optional":false,"format":16}},{"name":"votesRefund","type":{"kind":"simple","type":"uint","optional":false,"format":16}},{"name":"sellerStake","type":{"kind":"simple","type":"uint","optional":false,"format":"coins"}},{"name":"sellerStaked","type":{"kind":"simple","type":"bool","optional":false}},{"name":"requireSellerStake","type":{"kind":"simple","type":"bool","optional":false}},{"name":"baseSellerStake","type":{"kind":"simple","type":"uint","optional":false,"format":"coins"}},{"name":"requireRepCollateral","type":{"kind":"simple","type":"bool","optional":false}},{"name":"minRepScore","type":{"kind":"simple","type":"uint","optional":false,"format":8}}]},
2114
+ {"name":"Escrow$Data","header":null,"fields":[{"name":"depositor","type":{"kind":"simple","type":"address","optional":false}},{"name":"beneficiary","type":{"kind":"simple","type":"address","optional":false}},{"name":"reputationContract","type":{"kind":"simple","type":"address","optional":false}},{"name":"amount","type":{"kind":"simple","type":"uint","optional":false,"format":"coins"}},{"name":"deadline","type":{"kind":"simple","type":"uint","optional":false,"format":32}},{"name":"released","type":{"kind":"simple","type":"bool","optional":false}},{"name":"refunded","type":{"kind":"simple","type":"bool","optional":false}},{"name":"deliveryConfirmed","type":{"kind":"simple","type":"bool","optional":false}},{"name":"disputed","type":{"kind":"simple","type":"bool","optional":false}},{"name":"votingDeadline","type":{"kind":"simple","type":"uint","optional":false,"format":32}},{"name":"minArbiters","type":{"kind":"simple","type":"uint","optional":false,"format":8}},{"name":"minStake","type":{"kind":"simple","type":"uint","optional":false,"format":"coins"}},{"name":"arbiters","type":{"kind":"dict","key":"int","value":"address"}},{"name":"arbiterIndex","type":{"kind":"dict","key":"address","value":"int"}},{"name":"stakes","type":{"kind":"dict","key":"int","value":"int"}},{"name":"voted","type":{"kind":"dict","key":"int","value":"bool"}},{"name":"votes","type":{"kind":"dict","key":"int","value":"bool"}},{"name":"arbiterCount","type":{"kind":"simple","type":"uint","optional":false,"format":16}},{"name":"votesRelease","type":{"kind":"simple","type":"uint","optional":false,"format":16}},{"name":"votesRefund","type":{"kind":"simple","type":"uint","optional":false,"format":16}},{"name":"sellerStake","type":{"kind":"simple","type":"uint","optional":false,"format":"coins"}},{"name":"sellerStaked","type":{"kind":"simple","type":"bool","optional":false}},{"name":"requireSellerStake","type":{"kind":"simple","type":"bool","optional":false}},{"name":"baseSellerStake","type":{"kind":"simple","type":"uint","optional":false,"format":"coins"}},{"name":"requireRepCollateral","type":{"kind":"simple","type":"bool","optional":false}},{"name":"minRepScore","type":{"kind":"simple","type":"uint","optional":false,"format":8}},{"name":"totalArbiterStakes","type":{"kind":"simple","type":"uint","optional":false,"format":"coins"}}]},
2109
2115
  ]
2110
2116
 
2111
2117
  const Escrow_opcodes = {
package/src/utils.ts CHANGED
@@ -1,168 +1,168 @@
1
- import { existsSync, readFileSync, writeFileSync } from "fs";
2
- import { Address, internal, toNano, beginCell } from "@ton/core";
3
- import { TonClient4 } from "@ton/ton";
4
- import type { AgentContext } from "@ton-agent-kit/core";
5
- import {
6
- Escrow,
7
- storeDeploy,
8
- storeDeposit,
9
- storeRelease,
10
- storeRefund,
11
- storeDeliveryConfirmed,
12
- storeAutoRelease,
13
- storeOpenDispute,
14
- storeJoinDispute,
15
- storeVoteRelease,
16
- storeVoteRefund,
17
- storeClaimReward,
18
- storeFallbackSettle,
19
- storeSellerStake,
20
- } from "./contracts/Escrow_Escrow";
21
- import { sendTransaction } from "@ton-agent-kit/core";
22
-
23
- const ESCROW_FILE = ".escrow-store.json";
24
-
25
- export interface EscrowRecord {
26
- id: string;
27
- contractAddress: string;
28
- depositor: string;
29
- beneficiary: string;
30
- amount: string;
31
- deadline: number;
32
- deadlineISO: string;
33
- minArbiters: number;
34
- minStake: string;
35
- description: string;
36
- status: string;
37
- createdAt: string;
38
- }
39
-
40
- export function loadEscrows(): Record<string, EscrowRecord> {
41
- try {
42
- if (existsSync(ESCROW_FILE)) {
43
- return JSON.parse(readFileSync(ESCROW_FILE, "utf-8"));
44
- }
45
- } catch (err: any) {
46
- console.error(`Failed to load escrow store: ${err.message}`);
47
- }
48
- return {};
49
- }
50
-
51
- export function saveEscrows(escrows: Record<string, EscrowRecord>): void {
52
- try {
53
- writeFileSync(ESCROW_FILE, JSON.stringify(escrows, null, 2), "utf-8");
54
- } catch (err: any) {
55
- console.error(`Failed to save escrow store: ${err.message}`);
56
- }
57
- }
58
-
59
- // ── On-chain helpers ──
60
-
61
- export async function deployEscrowContract(
62
- agent: AgentContext,
63
- depositor: Address,
64
- beneficiary: Address,
65
- deadline: bigint,
66
- minArbiters: bigint,
67
- minStake: bigint,
68
- reputationContract: Address,
69
- requireRepCollateral: boolean,
70
- minRepScore: bigint,
71
- baseSellerStake: bigint,
72
- ): Promise<Address> {
73
- const escrow = await Escrow.fromInit(depositor, beneficiary, deadline, minArbiters, minStake, reputationContract, requireRepCollateral, minRepScore, baseSellerStake);
74
- const deployBody = beginCell()
75
- .store(storeDeploy({ $$type: "Deploy", queryId: 0n }))
76
- .endCell();
77
-
78
- await sendTransaction(agent, [
79
- internal({
80
- to: escrow.address,
81
- value: toNano("0.05"),
82
- bounce: false,
83
- init: escrow.init!,
84
- body: deployBody,
85
- }),
86
- ]);
87
- return escrow.address;
88
- }
89
-
90
- export async function depositToContract(agent: AgentContext, contractAddress: Address, amount: string): Promise<void> {
91
- const body = beginCell().store(storeDeposit({ $$type: "Deposit", queryId: 0n })).endCell();
92
- await sendTransaction(agent, [internal({ to: contractAddress, value: toNano(amount), bounce: true, body })]);
93
- }
94
-
95
- export async function releaseContract(agent: AgentContext, contractAddress: Address): Promise<void> {
96
- const body = beginCell().store(storeRelease({ $$type: "Release", queryId: 0n })).endCell();
97
- await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.05"), bounce: true, body })]);
98
- }
99
-
100
- export async function refundContract(agent: AgentContext, contractAddress: Address): Promise<void> {
101
- const body = beginCell().store(storeRefund({ $$type: "Refund", queryId: 0n })).endCell();
102
- await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.05"), bounce: true, body })]);
103
- }
104
-
105
- export async function confirmDeliveryOnContract(agent: AgentContext, contractAddress: Address, x402TxHash: string): Promise<void> {
106
- const body = beginCell().store(storeDeliveryConfirmed({ $$type: "DeliveryConfirmed", x402TxHash })).endCell();
107
- await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.05"), bounce: true, body })]);
108
- }
109
-
110
- export async function autoReleaseOnContract(agent: AgentContext, contractAddress: Address): Promise<void> {
111
- const body = beginCell().store(storeAutoRelease({ $$type: "AutoRelease" })).endCell();
112
- await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.05"), bounce: true, body })]);
113
- }
114
-
115
- export async function openDisputeOnContract(agent: AgentContext, contractAddress: Address): Promise<void> {
116
- const body = beginCell().store(storeOpenDispute({ $$type: "OpenDispute" })).endCell();
117
- // 0.08 TON: escrow gas + cross-contract notification to reputation. Excess refunded.
118
- await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.08"), bounce: true, body })]);
119
- }
120
-
121
- export async function joinDisputeOnContract(agent: AgentContext, contractAddress: Address, stakeAmount: string): Promise<void> {
122
- const body = beginCell().store(storeJoinDispute({ $$type: "JoinDispute" })).endCell();
123
- await sendTransaction(agent, [internal({ to: contractAddress, value: toNano(stakeAmount), bounce: true, body })]);
124
- }
125
-
126
- export async function voteReleaseOnContract(agent: AgentContext, contractAddress: Address): Promise<void> {
127
- const body = beginCell().store(storeVoteRelease({ $$type: "VoteRelease" })).endCell();
128
- await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.05"), bounce: true, body })]);
129
- }
130
-
131
- export async function voteRefundOnContract(agent: AgentContext, contractAddress: Address): Promise<void> {
132
- const body = beginCell().store(storeVoteRefund({ $$type: "VoteRefund" })).endCell();
133
- await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.05"), bounce: true, body })]);
134
- }
135
-
136
- export async function claimRewardOnContract(agent: AgentContext, contractAddress: Address): Promise<void> {
137
- const body = beginCell().store(storeClaimReward({ $$type: "ClaimReward" })).endCell();
138
- await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.05"), bounce: true, body })]);
139
- }
140
-
141
- export async function fallbackSettleOnContract(agent: AgentContext, contractAddress: Address): Promise<void> {
142
- const body = beginCell().store(storeFallbackSettle({ $$type: "FallbackSettle" })).endCell();
143
- await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.05"), bounce: true, body })]);
144
- }
145
-
146
- export async function sellerStakeOnContract(agent: AgentContext, contractAddress: Address, stakeAmount: string): Promise<void> {
147
- const body = beginCell().store(storeSellerStake({ $$type: "SellerStake" })).endCell();
148
- await sendTransaction(agent, [internal({ to: contractAddress, value: toNano(stakeAmount), bounce: true, body })]);
149
- }
150
-
151
- export async function getContractState(agent: AgentContext, contractAddress: Address) {
152
- const client = new TonClient4({ endpoint: agent.rpcUrl });
153
- const contract = client.open(Escrow.fromAddress(contractAddress));
154
- const data = await contract.getEscrowData();
155
- const balance = await contract.getBalance();
156
- return { ...data, balance };
157
- }
158
-
159
- export async function getLatestTxHash(address: string, network: "testnet" | "mainnet"): Promise<string> {
160
- const apiBase = network === "testnet" ? "https://testnet.tonapi.io/v2" : "https://tonapi.io/v2";
161
- try {
162
- const res = await fetch(`${apiBase}/accounts/${encodeURIComponent(address)}/events?limit=1`);
163
- const data = await res.json();
164
- return data.events?.[0]?.event_id || "pending";
165
- } catch {
166
- return "pending";
167
- }
168
- }
1
+ import { existsSync, readFileSync, writeFileSync } from "fs";
2
+ import { Address, internal, toNano, beginCell } from "@ton/core";
3
+ import { TonClient4 } from "@ton/ton";
4
+ import type { AgentContext } from "@ton-agent-kit/core";
5
+ import {
6
+ Escrow,
7
+ storeDeploy,
8
+ storeDeposit,
9
+ storeRelease,
10
+ storeRefund,
11
+ storeDeliveryConfirmed,
12
+ storeAutoRelease,
13
+ storeOpenDispute,
14
+ storeJoinDispute,
15
+ storeVoteRelease,
16
+ storeVoteRefund,
17
+ storeClaimReward,
18
+ storeFallbackSettle,
19
+ storeSellerStake,
20
+ } from "./contracts/Escrow_Escrow";
21
+ import { sendTransaction } from "@ton-agent-kit/core";
22
+
23
+ const ESCROW_FILE = ".escrow-store.json";
24
+
25
+ export interface EscrowRecord {
26
+ id: string;
27
+ contractAddress: string;
28
+ depositor: string;
29
+ beneficiary: string;
30
+ amount: string;
31
+ deadline: number;
32
+ deadlineISO: string;
33
+ minArbiters: number;
34
+ minStake: string;
35
+ description: string;
36
+ status: string;
37
+ createdAt: string;
38
+ }
39
+
40
+ export function loadEscrows(): Record<string, EscrowRecord> {
41
+ try {
42
+ if (existsSync(ESCROW_FILE)) {
43
+ return JSON.parse(readFileSync(ESCROW_FILE, "utf-8"));
44
+ }
45
+ } catch (err: any) {
46
+ console.error(`Failed to load escrow store: ${err.message}`);
47
+ }
48
+ return {};
49
+ }
50
+
51
+ export function saveEscrows(escrows: Record<string, EscrowRecord>): void {
52
+ try {
53
+ writeFileSync(ESCROW_FILE, JSON.stringify(escrows, null, 2), "utf-8");
54
+ } catch (err: any) {
55
+ console.error(`Failed to save escrow store: ${err.message}`);
56
+ }
57
+ }
58
+
59
+ // ── On-chain helpers ──
60
+
61
+ export async function deployEscrowContract(
62
+ agent: AgentContext,
63
+ depositor: Address,
64
+ beneficiary: Address,
65
+ deadline: bigint,
66
+ minArbiters: bigint,
67
+ minStake: bigint,
68
+ reputationContract: Address,
69
+ requireRepCollateral: boolean,
70
+ minRepScore: bigint,
71
+ baseSellerStake: bigint,
72
+ ): Promise<Address> {
73
+ const escrow = await Escrow.fromInit(depositor, beneficiary, deadline, minArbiters, minStake, reputationContract, requireRepCollateral, minRepScore, baseSellerStake);
74
+ const deployBody = beginCell()
75
+ .store(storeDeploy({ $$type: "Deploy", queryId: 0n }))
76
+ .endCell();
77
+
78
+ await sendTransaction(agent, [
79
+ internal({
80
+ to: escrow.address,
81
+ value: toNano("0.12"),
82
+ bounce: false,
83
+ init: escrow.init!,
84
+ body: deployBody,
85
+ }),
86
+ ]);
87
+ return escrow.address;
88
+ }
89
+
90
+ export async function depositToContract(agent: AgentContext, contractAddress: Address, amount: string): Promise<void> {
91
+ const body = beginCell().store(storeDeposit({ $$type: "Deposit", queryId: 0n })).endCell();
92
+ await sendTransaction(agent, [internal({ to: contractAddress, value: toNano(amount), bounce: true, body })]);
93
+ }
94
+
95
+ export async function releaseContract(agent: AgentContext, contractAddress: Address): Promise<void> {
96
+ const body = beginCell().store(storeRelease({ $$type: "Release", queryId: 0n })).endCell();
97
+ await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.12"), bounce: true, body })]);
98
+ }
99
+
100
+ export async function refundContract(agent: AgentContext, contractAddress: Address): Promise<void> {
101
+ const body = beginCell().store(storeRefund({ $$type: "Refund", queryId: 0n })).endCell();
102
+ await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.12"), bounce: true, body })]);
103
+ }
104
+
105
+ export async function confirmDeliveryOnContract(agent: AgentContext, contractAddress: Address, x402TxHash: string): Promise<void> {
106
+ const body = beginCell().store(storeDeliveryConfirmed({ $$type: "DeliveryConfirmed", x402TxHash })).endCell();
107
+ await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.12"), bounce: true, body })]);
108
+ }
109
+
110
+ export async function autoReleaseOnContract(agent: AgentContext, contractAddress: Address): Promise<void> {
111
+ const body = beginCell().store(storeAutoRelease({ $$type: "AutoRelease" })).endCell();
112
+ await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.12"), bounce: true, body })]);
113
+ }
114
+
115
+ export async function openDisputeOnContract(agent: AgentContext, contractAddress: Address): Promise<void> {
116
+ const body = beginCell().store(storeOpenDispute({ $$type: "OpenDispute" })).endCell();
117
+ // 0.15 TON: escrow gas + cross-contract notification to reputation. Excess refunded.
118
+ await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.15"), bounce: true, body })]);
119
+ }
120
+
121
+ export async function joinDisputeOnContract(agent: AgentContext, contractAddress: Address, stakeAmount: string): Promise<void> {
122
+ const body = beginCell().store(storeJoinDispute({ $$type: "JoinDispute" })).endCell();
123
+ await sendTransaction(agent, [internal({ to: contractAddress, value: toNano(stakeAmount), bounce: true, body })]);
124
+ }
125
+
126
+ export async function voteReleaseOnContract(agent: AgentContext, contractAddress: Address): Promise<void> {
127
+ const body = beginCell().store(storeVoteRelease({ $$type: "VoteRelease" })).endCell();
128
+ await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.12"), bounce: true, body })]);
129
+ }
130
+
131
+ export async function voteRefundOnContract(agent: AgentContext, contractAddress: Address): Promise<void> {
132
+ const body = beginCell().store(storeVoteRefund({ $$type: "VoteRefund" })).endCell();
133
+ await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.12"), bounce: true, body })]);
134
+ }
135
+
136
+ export async function claimRewardOnContract(agent: AgentContext, contractAddress: Address): Promise<void> {
137
+ const body = beginCell().store(storeClaimReward({ $$type: "ClaimReward" })).endCell();
138
+ await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.12"), bounce: true, body })]);
139
+ }
140
+
141
+ export async function fallbackSettleOnContract(agent: AgentContext, contractAddress: Address): Promise<void> {
142
+ const body = beginCell().store(storeFallbackSettle({ $$type: "FallbackSettle" })).endCell();
143
+ await sendTransaction(agent, [internal({ to: contractAddress, value: toNano("0.12"), bounce: true, body })]);
144
+ }
145
+
146
+ export async function sellerStakeOnContract(agent: AgentContext, contractAddress: Address, stakeAmount: string): Promise<void> {
147
+ const body = beginCell().store(storeSellerStake({ $$type: "SellerStake" })).endCell();
148
+ await sendTransaction(agent, [internal({ to: contractAddress, value: toNano(stakeAmount), bounce: true, body })]);
149
+ }
150
+
151
+ export async function getContractState(agent: AgentContext, contractAddress: Address) {
152
+ const client = new TonClient4({ endpoint: agent.rpcUrl });
153
+ const contract = client.open(Escrow.fromAddress(contractAddress));
154
+ const data = await contract.getEscrowData();
155
+ const balance = await contract.getBalance();
156
+ return { ...data, balance };
157
+ }
158
+
159
+ export async function getLatestTxHash(address: string, network: "testnet" | "mainnet"): Promise<string> {
160
+ const apiBase = network === "testnet" ? "https://testnet.tonapi.io/v2" : "https://tonapi.io/v2";
161
+ try {
162
+ const res = await fetch(`${apiBase}/accounts/${encodeURIComponent(address)}/events?limit=1`);
163
+ const data = await res.json();
164
+ return data.events?.[0]?.event_id || "pending";
165
+ } catch {
166
+ return "pending";
167
+ }
168
+ }