@msafe/sui3-sdk 0.0.15-pre-3e855d9.0 → 0.0.16

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/index.cjs CHANGED
@@ -155,6 +155,7 @@ var InvitationSDK = class {
155
155
 
156
156
  // src/core/MSafeAccount.ts
157
157
  var import_sui3_utils4 = require("@msafe/sui3-utils");
158
+ var import_transactions4 = require("@mysten/sui.js/transactions");
158
159
  var import_utils3 = require("@mysten/sui.js/utils");
159
160
 
160
161
  // src/transactions/coin-transfer.ts
@@ -685,28 +686,36 @@ var MSafeAccount = class _MSafeAccount {
685
686
  return getAllOwnedObjects(this.suiClient, this.address, filterCoinObjectOptions);
686
687
  }
687
688
  async pendingTransaction() {
688
- const pendings = await this.backend.getPendingTransactions(this.address);
689
- if (pendings.length > 2) {
690
- throw new Error(`invalid backend getPendingTransactions resp, length should not > 2: ${pendings}`);
691
- }
692
- if (pendings.length === 0) {
689
+ const res = await this.backend.getPendingTransactions({ msafeAddress: this.address });
690
+ if (!res.pending) {
693
691
  return void 0;
694
692
  }
695
- const pendingTx = pendings.find((tx) => !tx.isRejectTx);
696
- const rejectPending = pendings.find((tx) => tx.isRejectTx);
693
+ const pendingTx = res.pending;
694
+ const rejectPending = res.reject;
697
695
  return {
698
- ...pendingTx,
696
+ txType: import_sui3_utils4.TransactionType.Assets,
697
+ txSubType: import_sui3_utils4.TransactionSubTypes.assets.coin.send,
698
+ createdAt: pendingTx.createdAt,
699
+ creator: pendingTx.creator,
700
+ digest: pendingTx.digest,
701
+ intention: pendingTx.intention,
702
+ sequenceNumber: pendingTx.sequenceNumber,
703
+ payload: pendingTx.payload,
704
+ votes: pendingTx.votes,
705
+ msafeAddress: pendingTx.msafeAddress,
699
706
  rejectDigest: rejectPending?.digest ?? "",
700
707
  rejectPayload: rejectPending?.payload ?? "",
701
708
  rejectVotes: rejectPending?.votes ?? []
702
709
  };
703
710
  }
704
- async historyTransaction(paginationOption) {
705
- return this.backend.getHistoryTransactions(this.address, paginationOption);
711
+ async historyTransaction(pagination) {
712
+ return this.backend.getHistoryTransactions({
713
+ msafeAddress: this.address,
714
+ ...pagination
715
+ });
706
716
  }
707
- async futureIntentions(paginationOption) {
708
- const paginatedIntentions = await this.backend.getFutureIntentions(this.address, paginationOption);
709
- return paginatedIntentions.data;
717
+ async futureIntentions(pagination) {
718
+ return this.backend.getFutureIntentions({ msafeAddress: this.address, ...pagination });
710
719
  }
711
720
  async currentSequenceNumber() {
712
721
  return this.backend.getCurrentSequenceNumber(this.address);
@@ -726,17 +735,35 @@ var MSafeAccount = class _MSafeAccount {
726
735
  await this.backend.proposeIntention({
727
736
  ...input,
728
737
  msafeAddress: this.address,
729
- userAddress: await this.userAddress(),
730
738
  signature: signature.signature
731
739
  });
732
740
  }
741
+ async proposeCoinTransferIntention(intention) {
742
+ const sn = await this.nextSequenceNumber();
743
+ return this.proposeIntention({
744
+ application: import_sui3_utils4.TransactionDefaultApplication,
745
+ txType: import_sui3_utils4.TransactionType.Assets,
746
+ txSubType: import_sui3_utils4.TransactionSubTypes.assets.coin.send,
747
+ sequenceNumber: sn,
748
+ intention
749
+ });
750
+ }
751
+ async proposeObjectTransferIntention(intention) {
752
+ const sn = await this.nextSequenceNumber();
753
+ return this.proposeIntention({
754
+ application: import_sui3_utils4.TransactionDefaultApplication,
755
+ txType: import_sui3_utils4.TransactionType.Assets,
756
+ txSubType: import_sui3_utils4.TransactionSubTypes.assets.object.send,
757
+ sequenceNumber: sn,
758
+ intention
759
+ });
760
+ }
733
761
  async voteForTransaction(digest, payload) {
734
762
  const payloadBytes = HexToUint8Array(payload);
735
763
  const signature = await this.wallet.signTransactionBlock({ transactionBlock: payloadBytes });
736
764
  return this.backend.voteForTransaction({
737
765
  msafeAddress: this.address,
738
- userAddress: await this.userAddress(),
739
- txDigest: digest,
766
+ digest,
740
767
  signature: signature.signature
741
768
  });
742
769
  }
@@ -759,20 +786,12 @@ var MSafeAccount = class _MSafeAccount {
759
786
  signature: signature.signature
760
787
  });
761
788
  }
762
- async rejectCurrentTx(pending) {
763
- let payloadToReject;
764
- if (pending) {
765
- if (pending.isRejectTx) {
766
- throw new Error("Pending not reject transaction");
767
- }
768
- payloadToReject = pending.payload;
769
- } else {
770
- const pendingTx = await this.pendingTransaction();
771
- if (!pendingTx || pendingTx.rejectDigest !== "") {
772
- throw new Error("Already rejected");
773
- }
774
- payloadToReject = pendingTx.payload;
789
+ async rejectCurrentTx() {
790
+ const pendingTx = await this.pendingTransaction();
791
+ if (!pendingTx || pendingTx.rejectDigest !== "") {
792
+ throw new Error("Already rejected");
775
793
  }
794
+ const payloadToReject = pendingTx.payload;
776
795
  const rejectTxb = await IntentionHelper.buildRejectTransaction({
777
796
  msafeAddress: this.address,
778
797
  payloadToReject
@@ -782,7 +801,6 @@ var MSafeAccount = class _MSafeAccount {
782
801
  const signature = await this.wallet.signTransactionBlock({ transactionBlock: payload });
783
802
  return this.backend.rejectCurrentTx({
784
803
  msafeAddress: this.address,
785
- userAddress: await this.userAddress(),
786
804
  digest,
787
805
  signature: signature.signature
788
806
  });
@@ -791,10 +809,11 @@ var MSafeAccount = class _MSafeAccount {
791
809
  return this.backend.buildNextIntentionAndAddToPending({ msafeAddress: this.address });
792
810
  }
793
811
  async skipNextFailedIntention() {
794
- return this.backend.skipNextFailedIntention({ msafeAddress: this.address, userAddress: await this.userAddress() });
812
+ return this.backend.skipNextFailedIntention({ msafeAddress: this.address });
795
813
  }
796
814
  async simulateIntention(intention) {
797
- const txb = await (0, import_sui3_utils4.buildIntentionTransaction)(this.suiClient, intention, this.address);
815
+ const txb = new import_transactions4.TransactionBlock();
816
+ txb.setSender(this.address);
798
817
  if (!txb.blockData.gasConfig.price) {
799
818
  const refGas = await this.suiClient.getReferenceGasPrice();
800
819
  txb.setGasPrice(refGas);
@@ -1023,8 +1042,9 @@ var BackendImpl = class _BackendImpl {
1023
1042
  throw new Error(`Invalid updateMSafeStatus return: ${res}`);
1024
1043
  }
1025
1044
  }
1026
- async getPendingTransactions(msafeAddress) {
1027
- const res = await import_axios.default.get(`${this.apiURL}/transaction/pending/${msafeAddress}`, {
1045
+ async getPendingTransactions(input) {
1046
+ const res = await import_axios.default.get(`${this.apiURL}/transaction/pending`, {
1047
+ params: input,
1028
1048
  headers: this.headers()
1029
1049
  });
1030
1050
  if (res.status !== 200 && res.status !== 201) {
@@ -1032,28 +1052,19 @@ var BackendImpl = class _BackendImpl {
1032
1052
  }
1033
1053
  return res.data;
1034
1054
  }
1035
- async getHistoryTransactions(msafeAddress, paginationOption) {
1036
- const res = await import_axios.default.get(
1037
- `${this.apiURL}/transaction/history?address=${msafeAddress}`,
1038
- {
1039
- params: {
1040
- page: paginationOption?.page,
1041
- limit: paginationOption?.limit
1042
- },
1043
- headers: this.headers()
1044
- }
1045
- );
1055
+ async getHistoryTransactions(input) {
1056
+ const res = await import_axios.default.get(`${this.apiURL}/transaction/history`, {
1057
+ params: input,
1058
+ headers: this.headers()
1059
+ });
1046
1060
  if (res.status !== 200 && res.status !== 201) {
1047
1061
  throw new Error(`invalid getCurrentSequenceNumber return: ${res}`);
1048
1062
  }
1049
1063
  return res.data;
1050
1064
  }
1051
- async getFutureIntentions(msafeAddress, paginationOption) {
1052
- const res = await import_axios.default.get(`${this.apiURL}/transaction/intention/${msafeAddress}`, {
1053
- params: {
1054
- page: paginationOption?.page,
1055
- limit: paginationOption?.limit
1056
- },
1065
+ async getFutureIntentions(input) {
1066
+ const res = await import_axios.default.get(`${this.apiURL}/transaction/intention`, {
1067
+ params: input,
1057
1068
  headers: this.headers()
1058
1069
  });
1059
1070
  if (res.status !== 200 && res.status !== 201) {
@@ -1061,8 +1072,11 @@ var BackendImpl = class _BackendImpl {
1061
1072
  }
1062
1073
  return res.data;
1063
1074
  }
1064
- async getCurrentSequenceNumber(msafeAddress) {
1065
- const res = await import_axios.default.get(`${this.apiURL}/transaction/sn/current/${msafeAddress}`, {
1075
+ async getCurrentSequenceNumber(address) {
1076
+ const res = await import_axios.default.get(`${this.apiURL}/transaction/sn/current`, {
1077
+ params: {
1078
+ msafeAddress: address
1079
+ },
1066
1080
  headers: this.headers()
1067
1081
  });
1068
1082
  if (res.status !== 200 && res.status !== 201) {
@@ -1070,8 +1084,11 @@ var BackendImpl = class _BackendImpl {
1070
1084
  }
1071
1085
  return res.data;
1072
1086
  }
1073
- async getNextSequenceNumber(msafeAddress) {
1074
- const res = await import_axios.default.get(`${this.apiURL}/transaction/sn/next/${msafeAddress}`, {
1087
+ async getNextSequenceNumber(address) {
1088
+ const res = await import_axios.default.get(`${this.apiURL}/transaction/sn/next`, {
1089
+ params: {
1090
+ msafeAddress: address
1091
+ },
1075
1092
  headers: this.headers()
1076
1093
  });
1077
1094
  if (res.status !== 200 && res.status !== 201) {
@@ -1099,57 +1116,29 @@ var BackendImpl = class _BackendImpl {
1099
1116
  return void 0;
1100
1117
  }
1101
1118
  async rejectCurrentTx(input) {
1102
- const res = await import_axios.default.post(
1103
- `${this.apiURL}/transaction/pending/reject`,
1104
- {
1105
- address: input.msafeAddress,
1106
- digest: input.digest,
1107
- signature: input.signature
1108
- },
1109
- {
1110
- headers: this.headers()
1111
- }
1112
- );
1119
+ const res = await import_axios.default.post(`${this.apiURL}/transaction/pending/reject`, input, {
1120
+ headers: this.headers()
1121
+ });
1113
1122
  if (res.status !== 200 && res.status !== 201) {
1114
1123
  throw new Error(`invalid voteForTransaction return: ${res}`);
1115
1124
  }
1116
1125
  }
1117
1126
  async voteForTransaction(input) {
1118
- const res = await import_axios.default.post(
1119
- `${this.apiURL}/transaction/pending/vote`,
1120
- {
1121
- address: input.msafeAddress,
1122
- digest: input.txDigest,
1123
- signature: input.signature
1124
- },
1125
- {
1126
- headers: this.headers()
1127
- }
1128
- );
1127
+ const res = await import_axios.default.post(`${this.apiURL}/transaction/pending/vote`, input, {
1128
+ headers: this.headers()
1129
+ });
1129
1130
  if (res.status !== 200 && res.status !== 201) {
1130
1131
  throw new Error(`invalid voteForTransaction return: ${res}`);
1131
1132
  }
1132
1133
  }
1133
1134
  async buildNextIntentionAndAddToPending(input) {
1134
- const res = await import_axios.default.post(
1135
- `${this.apiURL}/transaction/pending/build`,
1136
- {
1137
- address: input.msafeAddress
1138
- },
1139
- { headers: this.headers() }
1140
- );
1135
+ const res = await import_axios.default.post(`${this.apiURL}/transaction/pending/build`, input, { headers: this.headers() });
1141
1136
  if (res.status !== 200 && res.status !== 201) {
1142
1137
  throw new Error(`invalid buildNextIntentionAndAddToPending return: ${res}`);
1143
1138
  }
1144
1139
  }
1145
1140
  async skipNextFailedIntention(input) {
1146
- const res = await import_axios.default.post(
1147
- `${this.apiURL}/transaction/pending/skip`,
1148
- {
1149
- msafeAddress: input.msafeAddress
1150
- },
1151
- { headers: this.headers() }
1152
- );
1141
+ const res = await import_axios.default.post(`${this.apiURL}/transaction/pending/skip`, input, { headers: this.headers() });
1153
1142
  if (res.status !== 200 && res.status !== 201) {
1154
1143
  throw new Error(`invalid skipNextFailedIntention return: ${res}`);
1155
1144
  }