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

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,34 @@ 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
+ createdAt: pendingTx.createAt,
697
+ creator: pendingTx.creator,
698
+ digest: pendingTx.digest,
699
+ intention: pendingTx.intention,
700
+ sequenceNumber: pendingTx.sequenceNumber,
701
+ payload: pendingTx.payload,
702
+ votes: pendingTx.votes,
703
+ msafeAddress: pendingTx.msafeAddress,
699
704
  rejectDigest: rejectPending?.digest ?? "",
700
705
  rejectPayload: rejectPending?.payload ?? "",
701
706
  rejectVotes: rejectPending?.votes ?? []
702
707
  };
703
708
  }
704
- async historyTransaction(paginationOption) {
705
- return this.backend.getHistoryTransactions(this.address, paginationOption);
709
+ async historyTransaction(pagination) {
710
+ return this.backend.getHistoryTransactions({
711
+ msafeAddress: this.address,
712
+ ...pagination
713
+ });
706
714
  }
707
- async futureIntentions(paginationOption) {
708
- const paginatedIntentions = await this.backend.getFutureIntentions(this.address, paginationOption);
709
- return paginatedIntentions.data;
715
+ async futureIntentions(pagination) {
716
+ return this.backend.getFutureIntentions({ msafeAddress: this.address, ...pagination });
710
717
  }
711
718
  async currentSequenceNumber() {
712
719
  return this.backend.getCurrentSequenceNumber(this.address);
@@ -726,17 +733,35 @@ var MSafeAccount = class _MSafeAccount {
726
733
  await this.backend.proposeIntention({
727
734
  ...input,
728
735
  msafeAddress: this.address,
729
- userAddress: await this.userAddress(),
730
736
  signature: signature.signature
731
737
  });
732
738
  }
739
+ async proposeCoinTransferIntention(intention) {
740
+ const sn = await this.nextSequenceNumber();
741
+ return this.proposeIntention({
742
+ application: import_sui3_utils4.TransactionDefaultApplication,
743
+ txType: import_sui3_utils4.TransactionType.Assets,
744
+ txSubType: import_sui3_utils4.TransactionSubTypes.assets.coin.send,
745
+ sequenceNumber: sn,
746
+ intention
747
+ });
748
+ }
749
+ async proposeObjectTransferIntention(intention) {
750
+ const sn = await this.nextSequenceNumber();
751
+ return this.proposeIntention({
752
+ application: import_sui3_utils4.TransactionDefaultApplication,
753
+ txType: import_sui3_utils4.TransactionType.Assets,
754
+ txSubType: import_sui3_utils4.TransactionSubTypes.assets.object.send,
755
+ sequenceNumber: sn,
756
+ intention
757
+ });
758
+ }
733
759
  async voteForTransaction(digest, payload) {
734
760
  const payloadBytes = HexToUint8Array(payload);
735
761
  const signature = await this.wallet.signTransactionBlock({ transactionBlock: payloadBytes });
736
762
  return this.backend.voteForTransaction({
737
763
  msafeAddress: this.address,
738
- userAddress: await this.userAddress(),
739
- txDigest: digest,
764
+ digest,
740
765
  signature: signature.signature
741
766
  });
742
767
  }
@@ -759,20 +784,12 @@ var MSafeAccount = class _MSafeAccount {
759
784
  signature: signature.signature
760
785
  });
761
786
  }
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;
787
+ async rejectCurrentTx() {
788
+ const pendingTx = await this.pendingTransaction();
789
+ if (!pendingTx || pendingTx.rejectDigest !== "") {
790
+ throw new Error("Already rejected");
775
791
  }
792
+ const payloadToReject = pendingTx.payload;
776
793
  const rejectTxb = await IntentionHelper.buildRejectTransaction({
777
794
  msafeAddress: this.address,
778
795
  payloadToReject
@@ -782,7 +799,6 @@ var MSafeAccount = class _MSafeAccount {
782
799
  const signature = await this.wallet.signTransactionBlock({ transactionBlock: payload });
783
800
  return this.backend.rejectCurrentTx({
784
801
  msafeAddress: this.address,
785
- userAddress: await this.userAddress(),
786
802
  digest,
787
803
  signature: signature.signature
788
804
  });
@@ -791,10 +807,11 @@ var MSafeAccount = class _MSafeAccount {
791
807
  return this.backend.buildNextIntentionAndAddToPending({ msafeAddress: this.address });
792
808
  }
793
809
  async skipNextFailedIntention() {
794
- return this.backend.skipNextFailedIntention({ msafeAddress: this.address, userAddress: await this.userAddress() });
810
+ return this.backend.skipNextFailedIntention({ msafeAddress: this.address });
795
811
  }
796
812
  async simulateIntention(intention) {
797
- const txb = await (0, import_sui3_utils4.buildIntentionTransaction)(this.suiClient, intention, this.address);
813
+ const txb = new import_transactions4.TransactionBlock();
814
+ txb.setSender(this.address);
798
815
  if (!txb.blockData.gasConfig.price) {
799
816
  const refGas = await this.suiClient.getReferenceGasPrice();
800
817
  txb.setGasPrice(refGas);
@@ -1023,8 +1040,9 @@ var BackendImpl = class _BackendImpl {
1023
1040
  throw new Error(`Invalid updateMSafeStatus return: ${res}`);
1024
1041
  }
1025
1042
  }
1026
- async getPendingTransactions(msafeAddress) {
1027
- const res = await import_axios.default.get(`${this.apiURL}/transaction/pending/${msafeAddress}`, {
1043
+ async getPendingTransactions(input) {
1044
+ const res = await import_axios.default.get(`${this.apiURL}/transaction/pending`, {
1045
+ params: input,
1028
1046
  headers: this.headers()
1029
1047
  });
1030
1048
  if (res.status !== 200 && res.status !== 201) {
@@ -1032,28 +1050,19 @@ var BackendImpl = class _BackendImpl {
1032
1050
  }
1033
1051
  return res.data;
1034
1052
  }
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
- );
1053
+ async getHistoryTransactions(input) {
1054
+ const res = await import_axios.default.get(`${this.apiURL}/transaction/history`, {
1055
+ params: input,
1056
+ headers: this.headers()
1057
+ });
1046
1058
  if (res.status !== 200 && res.status !== 201) {
1047
1059
  throw new Error(`invalid getCurrentSequenceNumber return: ${res}`);
1048
1060
  }
1049
1061
  return res.data;
1050
1062
  }
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
- },
1063
+ async getFutureIntentions(input) {
1064
+ const res = await import_axios.default.get(`${this.apiURL}/transaction/intention`, {
1065
+ params: input,
1057
1066
  headers: this.headers()
1058
1067
  });
1059
1068
  if (res.status !== 200 && res.status !== 201) {
@@ -1061,8 +1070,11 @@ var BackendImpl = class _BackendImpl {
1061
1070
  }
1062
1071
  return res.data;
1063
1072
  }
1064
- async getCurrentSequenceNumber(msafeAddress) {
1065
- const res = await import_axios.default.get(`${this.apiURL}/transaction/sn/current/${msafeAddress}`, {
1073
+ async getCurrentSequenceNumber(address) {
1074
+ const res = await import_axios.default.get(`${this.apiURL}/transaction/sn/current`, {
1075
+ params: {
1076
+ msafeAddress: address
1077
+ },
1066
1078
  headers: this.headers()
1067
1079
  });
1068
1080
  if (res.status !== 200 && res.status !== 201) {
@@ -1070,8 +1082,11 @@ var BackendImpl = class _BackendImpl {
1070
1082
  }
1071
1083
  return res.data;
1072
1084
  }
1073
- async getNextSequenceNumber(msafeAddress) {
1074
- const res = await import_axios.default.get(`${this.apiURL}/transaction/sn/next/${msafeAddress}`, {
1085
+ async getNextSequenceNumber(address) {
1086
+ const res = await import_axios.default.get(`${this.apiURL}/transaction/sn/next`, {
1087
+ params: {
1088
+ msafeAddress: address
1089
+ },
1075
1090
  headers: this.headers()
1076
1091
  });
1077
1092
  if (res.status !== 200 && res.status !== 201) {
@@ -1099,57 +1114,29 @@ var BackendImpl = class _BackendImpl {
1099
1114
  return void 0;
1100
1115
  }
1101
1116
  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
- );
1117
+ const res = await import_axios.default.post(`${this.apiURL}/transaction/pending/reject`, input, {
1118
+ headers: this.headers()
1119
+ });
1113
1120
  if (res.status !== 200 && res.status !== 201) {
1114
1121
  throw new Error(`invalid voteForTransaction return: ${res}`);
1115
1122
  }
1116
1123
  }
1117
1124
  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
- );
1125
+ const res = await import_axios.default.post(`${this.apiURL}/transaction/pending/vote`, input, {
1126
+ headers: this.headers()
1127
+ });
1129
1128
  if (res.status !== 200 && res.status !== 201) {
1130
1129
  throw new Error(`invalid voteForTransaction return: ${res}`);
1131
1130
  }
1132
1131
  }
1133
1132
  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
- );
1133
+ const res = await import_axios.default.post(`${this.apiURL}/transaction/pending/build`, input, { headers: this.headers() });
1141
1134
  if (res.status !== 200 && res.status !== 201) {
1142
1135
  throw new Error(`invalid buildNextIntentionAndAddToPending return: ${res}`);
1143
1136
  }
1144
1137
  }
1145
1138
  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
- );
1139
+ const res = await import_axios.default.post(`${this.apiURL}/transaction/pending/skip`, input, { headers: this.headers() });
1153
1140
  if (res.status !== 200 && res.status !== 201) {
1154
1141
  throw new Error(`invalid skipNextFailedIntention return: ${res}`);
1155
1142
  }