@suilend/sui-fe 0.3.52 → 0.4.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/lib/keypair.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,44 +7,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.returnAllOwnedObjectsAndSuiToUser = exports.fundKeypair = exports.checkIfKeypairCanBeUsed = exports.createKeypair = exports.KEYPAIR_SEED_MESSAGE = exports.onSign = exports.checkLastTransactionSignature = exports.keypairSignExecuteAndWaitForTransaction = exports.keypairWaitForTransaction = exports.TransactionStatusError = void 0;
16
- const ed25519_1 = require("@mysten/sui/keypairs/ed25519");
17
- const transactions_1 = require("@mysten/sui/transactions");
18
- const utils_1 = require("@mysten/sui/utils");
19
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
20
- const coinType_1 = require("./coinType");
21
- const transactions_2 = require("./transactions");
22
- const constants_1 = require("./constants");
10
+ import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
11
+ import { Transaction, } from "@mysten/sui/transactions";
12
+ import { fromBase64, toHex } from "@mysten/sui/utils";
13
+ import BigNumber from "bignumber.js";
14
+ import { isSui } from "./coinType";
15
+ import { getAllCoins, getAllOwnedObjects, getMostRecentAddressTransaction, mergeAllCoins, } from "./transactions";
16
+ import { API_URL } from "./constants";
23
17
  // SIGN, EXECUTE, AND WAIT FOR
24
- class TransactionStatusError extends Error {
18
+ export class TransactionStatusError extends Error {
25
19
  constructor(message) {
26
20
  super(message);
27
21
  this.name = "TransactionStatusError";
28
22
  }
29
23
  }
30
- exports.TransactionStatusError = TransactionStatusError;
31
- const keypairWaitForTransaction = (digest, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
32
- var _a, _b;
33
- const res = yield suiClient.waitForTransaction({
24
+ export const keypairWaitForTransaction = (digest, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
25
+ var _a, _b, _c, _d, _e, _f, _g;
26
+ const res = yield suiClient.core.waitForTransaction({
34
27
  digest,
35
- options: {
36
- showBalanceChanges: true,
37
- showEffects: true,
38
- showEvents: true,
39
- showObjectChanges: true,
28
+ include: {
29
+ balanceChanges: true,
30
+ effects: true,
31
+ events: true,
32
+ objectChanges: true,
40
33
  },
41
34
  });
42
- if (((_a = res.effects) === null || _a === void 0 ? void 0 : _a.status) !== undefined &&
43
- res.effects.status.status === "failure")
44
- throw new TransactionStatusError((_b = res.effects.status.error) !== null && _b !== void 0 ? _b : "Transaction failed");
35
+ if (((_b = (_a = res.Transaction) === null || _a === void 0 ? void 0 : _a.effects) === null || _b === void 0 ? void 0 : _b.status) !== undefined &&
36
+ !!((_d = (_c = res.Transaction) === null || _c === void 0 ? void 0 : _c.effects) === null || _d === void 0 ? void 0 : _d.status.error))
37
+ throw new TransactionStatusError((_g = (_f = (_e = res.Transaction) === null || _e === void 0 ? void 0 : _e.effects) === null || _f === void 0 ? void 0 : _f.status.error.message) !== null && _g !== void 0 ? _g : "Transaction failed");
45
38
  return res;
46
39
  });
47
- exports.keypairWaitForTransaction = keypairWaitForTransaction;
48
- const keypairSignExecuteAndWaitForTransaction = (transaction, keypair, suiClient, onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
40
+ export const keypairSignExecuteAndWaitForTransaction = (transaction, keypair, suiClient, onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
41
+ var _a, _b;
49
42
  // 1) Sign
50
43
  const builtTransaction = yield transaction.build({
51
44
  client: suiClient,
@@ -53,28 +46,27 @@ const keypairSignExecuteAndWaitForTransaction = (transaction, keypair, suiClient
53
46
  const signedTransaction = yield keypair.signTransaction(builtTransaction);
54
47
  onSign === null || onSign === void 0 ? void 0 : onSign(signedTransaction);
55
48
  // 2) Execute
56
- const res1 = yield suiClient.executeTransactionBlock({
57
- transactionBlock: signedTransaction.bytes,
58
- signature: signedTransaction.signature,
49
+ const res1 = yield suiClient.core.executeTransaction({
50
+ transaction: builtTransaction,
51
+ signatures: [signedTransaction.signature],
59
52
  });
60
53
  onExecute === null || onExecute === void 0 ? void 0 : onExecute(res1);
61
54
  // 3) Wait
62
- const res2 = yield (0, exports.keypairWaitForTransaction)(res1.digest, suiClient);
55
+ const res2 = yield keypairWaitForTransaction((_b = (_a = res1.Transaction) === null || _a === void 0 ? void 0 : _a.digest) !== null && _b !== void 0 ? _b : "", suiClient);
63
56
  return res2;
64
57
  });
65
- exports.keypairSignExecuteAndWaitForTransaction = keypairSignExecuteAndWaitForTransaction;
66
- const checkLastTransactionSignature = (type, lastCurrentFlowTransaction, lastSignedTransaction, setLastSignedTransaction, suiClient, validCallback, invalidCallback) => __awaiter(void 0, void 0, void 0, function* () {
67
- var _a, _b;
58
+ export const checkLastTransactionSignature = (type, lastCurrentFlowTransaction, lastSignedTransaction, setLastSignedTransaction, suiClient, validCallback, invalidCallback) => __awaiter(void 0, void 0, void 0, function* () {
59
+ var _a, _b, _c, _d;
68
60
  console.log("[checkLastTransactionSignature]", {
69
61
  type,
70
62
  lastCurrentFlowTransaction,
71
63
  lastSignedTransaction,
72
64
  });
73
65
  if ((lastSignedTransaction === null || lastSignedTransaction === void 0 ? void 0 : lastSignedTransaction.type) === type &&
74
- ((_b = (_a = lastCurrentFlowTransaction === null || lastCurrentFlowTransaction === void 0 ? void 0 : lastCurrentFlowTransaction.transaction) === null || _a === void 0 ? void 0 : _a.txSignatures) !== null && _b !== void 0 ? _b : []).includes(lastSignedTransaction.signedTransaction.signature)) {
66
+ ((_b = (_a = lastCurrentFlowTransaction === null || lastCurrentFlowTransaction === void 0 ? void 0 : lastCurrentFlowTransaction.Transaction) === null || _a === void 0 ? void 0 : _a.signatures) !== null && _b !== void 0 ? _b : []).includes(lastSignedTransaction.signedTransaction.signature)) {
75
67
  console.log("[checkLastTransactionSignature] lastSignedTransaction type and signature MATCH");
76
68
  try {
77
- const res = yield (0, exports.keypairWaitForTransaction)(lastCurrentFlowTransaction.digest, suiClient); // Assumed to only throw if the transaction was executed but failed (e.g. insufficient gas), or if the connection was lost
69
+ const res = yield keypairWaitForTransaction((_d = (_c = lastCurrentFlowTransaction === null || lastCurrentFlowTransaction === void 0 ? void 0 : lastCurrentFlowTransaction.Transaction) === null || _c === void 0 ? void 0 : _c.digest) !== null && _d !== void 0 ? _d : "", suiClient); // Assumed to only throw if the transaction was executed but failed (e.g. insufficient gas), or if the connection was lost
78
70
  yield validCallback(res);
79
71
  setLastSignedTransaction(undefined);
80
72
  }
@@ -96,8 +88,7 @@ const checkLastTransactionSignature = (type, lastCurrentFlowTransaction, lastSig
96
88
  yield invalidCallback();
97
89
  }
98
90
  });
99
- exports.checkLastTransactionSignature = checkLastTransactionSignature;
100
- const onSign = (type, setLastSignedTransaction, index) => {
91
+ export const onSign = (type, setLastSignedTransaction, index) => {
101
92
  return (signedTransaction) => {
102
93
  console.log(`[onSign] Setting setLastSignedTransaction for ${type}${index !== undefined ? ` ${index}` : ""}`);
103
94
  setLastSignedTransaction({
@@ -106,17 +97,16 @@ const onSign = (type, setLastSignedTransaction, index) => {
106
97
  });
107
98
  };
108
99
  };
109
- exports.onSign = onSign;
110
100
  // CREATE KEYPAIR
111
- exports.KEYPAIR_SEED_MESSAGE = "send:wallet-connect";
112
- const createKeypair = (signature) => __awaiter(void 0, void 0, void 0, function* () {
113
- const signatureBytes = (0, utils_1.fromBase64)(signature);
114
- const signatureHex = (0, utils_1.toHex)(signatureBytes);
115
- const keypair = ed25519_1.Ed25519Keypair.deriveKeypairFromSeed(signatureHex);
101
+ export const KEYPAIR_SEED_MESSAGE = "send:wallet-connect";
102
+ export const createKeypair = (signature) => __awaiter(void 0, void 0, void 0, function* () {
103
+ const signatureBytes = fromBase64(signature);
104
+ const signatureHex = toHex(signatureBytes);
105
+ const keypair = Ed25519Keypair.deriveKeypairFromSeed(signatureHex);
116
106
  const address = keypair.toSuiAddress();
117
107
  const privateKey = keypair.getSecretKey();
118
108
  console.log("[createKeypair] keypair:", keypair, "address:", address);
119
- yield fetch(`${constants_1.API_URL}/steamm/proxy-wallet-mapping`, {
109
+ yield fetch(`${API_URL}/steamm/proxy-wallet-mapping`, {
120
110
  method: "POST",
121
111
  body: JSON.stringify({
122
112
  proxyWalletAddress: address,
@@ -126,13 +116,12 @@ const createKeypair = (signature) => __awaiter(void 0, void 0, void 0, function*
126
116
  });
127
117
  return { keypair, address, privateKey };
128
118
  });
129
- exports.createKeypair = createKeypair;
130
119
  // CHECK IF KEYPAIR CAN BE USED
131
- const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigests, keypair, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
120
+ export const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigests, keypair, suiClient, suiJsonRpcClient) => __awaiter(void 0, void 0, void 0, function* () {
132
121
  var _a, _b;
133
122
  const [mostRecentFromAddressTransaction, mostRecentToAddressTransaction] = yield Promise.all([
134
- (0, transactions_2.getMostRecentAddressTransaction)(suiClient, keypair.toSuiAddress(), "from"),
135
- (0, transactions_2.getMostRecentAddressTransaction)(suiClient, keypair.toSuiAddress(), "to"),
123
+ getMostRecentAddressTransaction(suiJsonRpcClient, keypair.toSuiAddress(), "from"),
124
+ getMostRecentAddressTransaction(suiJsonRpcClient, keypair.toSuiAddress(), "to"),
136
125
  ]);
137
126
  const mostRecentFromOrToAddressTransaction = [
138
127
  mostRecentFromAddressTransaction,
@@ -158,7 +147,7 @@ const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigests, keyp
158
147
  }
159
148
  else {
160
149
  // 3) Check if wallet has no owned objects
161
- const ownedObjectIds = (yield (0, transactions_2.getAllOwnedObjects)(suiClient, keypair.toSuiAddress())).map((obj) => { var _a; return (_a = obj.data) === null || _a === void 0 ? void 0 : _a.objectId; });
150
+ const ownedObjectIds = (yield getAllOwnedObjects(suiClient, keypair.toSuiAddress())).map((obj) => obj.objectId);
162
151
  console.log("[checkIfKeypairCanBeUsed] ownedObjectIds:", ownedObjectIds);
163
152
  if (ownedObjectIds.length === 0) {
164
153
  // Previous flow completed
@@ -184,8 +173,7 @@ const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigests, keyp
184
173
  }
185
174
  }
186
175
  });
187
- exports.checkIfKeypairCanBeUsed = checkIfKeypairCanBeUsed;
188
- const fundKeypair = (tokens, address, keypair, suiClient, signExecuteAndWaitForTransaction, // From WalletContext
176
+ export const fundKeypair = (tokens, address, keypair, suiClient, signExecuteAndWaitForTransaction, // From WalletContext
189
177
  onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
190
178
  const filteredTokens = tokens.filter((t) => t.amount.gt(0));
191
179
  console.log("[fundKeypair] tokens:", tokens.map((t) => ({
@@ -195,19 +183,19 @@ onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
195
183
  coinType: t.coinType,
196
184
  amount: t.amount.toString(),
197
185
  })));
198
- const allCoins = yield Promise.all(filteredTokens.map((token) => (0, transactions_2.getAllCoins)(suiClient, address, token.coinType)));
199
- const transaction = new transactions_1.Transaction();
186
+ const allCoins = yield Promise.all(filteredTokens.map((token) => getAllCoins(suiClient, address, token.coinType)));
187
+ const transaction = new Transaction();
200
188
  transaction.setSender(address);
201
- const mergeCoins = filteredTokens.map((token, index) => (0, transactions_2.mergeAllCoins)(token.coinType, transaction, allCoins[index]));
189
+ const mergeCoins = filteredTokens.map((token, index) => mergeAllCoins(token.coinType, transaction, allCoins[index]));
202
190
  const coins = [];
203
191
  for (let i = 0; i < filteredTokens.length; i++) {
204
192
  const token = filteredTokens[i];
205
- const [coin] = transaction.splitCoins((0, coinType_1.isSui)(token.coinType)
193
+ const [coin] = transaction.splitCoins(isSui(token.coinType)
206
194
  ? transaction.gas
207
- : transaction.object(mergeCoins[i].coinObjectId), [
195
+ : transaction.object(mergeCoins[i].objectId), [
208
196
  BigInt(token
209
197
  .amount.times(10 ** token.decimals)
210
- .integerValue(bignumber_js_1.default.ROUND_DOWN)
198
+ .integerValue(BigNumber.ROUND_DOWN)
211
199
  .toString()),
212
200
  ]);
213
201
  coins.push(coin);
@@ -216,19 +204,17 @@ onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
216
204
  const res = yield signExecuteAndWaitForTransaction(transaction, undefined, undefined, onSign, onExecute);
217
205
  return { res };
218
206
  });
219
- exports.fundKeypair = fundKeypair;
220
- const returnAllOwnedObjectsAndSuiToUser = (address, keypair, suiClient, onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
207
+ export const returnAllOwnedObjectsAndSuiToUser = (address, keypair, suiClient, onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
221
208
  console.log(`[returnAllOwnedObjectsAndSuiToUser] address: ${address}`);
222
- const transaction = new transactions_1.Transaction();
209
+ const transaction = new Transaction();
223
210
  transaction.setSender(keypair.toSuiAddress());
224
211
  transaction.transferObjects([transaction.gas], address); // Will throw if there is no gas
225
- const ownedObjectIds = (yield (0, transactions_2.getAllOwnedObjects)(suiClient, keypair.toSuiAddress()))
226
- .filter((obj) => { var _a; return ((_a = obj.data) === null || _a === void 0 ? void 0 : _a.content).type !== "0x2::coin::Coin<0x2::sui::SUI>"; })
227
- .map((obj) => { var _a; return (_a = obj.data) === null || _a === void 0 ? void 0 : _a.objectId; }); // Assumed to be <512 objects
212
+ const ownedObjectIds = (yield getAllOwnedObjects(suiClient, keypair.toSuiAddress()))
213
+ .filter((obj) => obj.type !== "0x2::coin::Coin<0x2::sui::SUI>")
214
+ .map((obj) => obj.objectId); // Assumed to be <512 objects
228
215
  console.log(`[returnAllOwnedObjectsAndSuiToUser] ownedObjectIds: ${ownedObjectIds}`);
229
216
  if (ownedObjectIds.length > 0)
230
217
  transaction.transferObjects(ownedObjectIds, address);
231
- const res = yield (0, exports.keypairSignExecuteAndWaitForTransaction)(transaction, keypair, suiClient, onSign, onExecute);
218
+ const res = yield keypairSignExecuteAndWaitForTransaction(transaction, keypair, suiClient, onSign, onExecute);
232
219
  return { res };
233
220
  });
234
- exports.returnAllOwnedObjectsAndSuiToUser = returnAllOwnedObjectsAndSuiToUser;
package/lib/ledger.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { SuiClient } from "@mysten/sui/client";
1
+ import { SuiGrpcClient } from "@mysten/sui/grpc";
2
2
  import { Transaction } from "@mysten/sui/transactions";
3
- export declare const getLedgerHash: (address: string, transaction: Transaction, suiClient: SuiClient) => Promise<string>;
3
+ export declare const getLedgerHash: (address: string, transaction: Transaction, suiClient: SuiGrpcClient) => Promise<string>;
package/lib/ledger.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,26 +7,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getLedgerHash = void 0;
16
- const cryptography_1 = require("@mysten/sui/cryptography");
17
- const transactions_1 = require("@mysten/sui/transactions");
18
- const blake2b_1 = __importDefault(require("blake2b"));
19
- const getLedgerHash = (address, transaction, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
10
+ import { messageWithIntent } from "@mysten/sui/cryptography";
11
+ import { Transaction } from "@mysten/sui/transactions";
12
+ import blake2b from "blake2b";
13
+ export const getLedgerHash = (address, transaction, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
20
14
  // Build transaction
21
- const _transaction = transactions_1.Transaction.from(transaction);
15
+ const _transaction = Transaction.from(transaction);
22
16
  _transaction.setSender(address);
23
17
  const builtTransaction = yield _transaction.build({
24
18
  client: suiClient,
25
19
  });
26
20
  // Get hash
27
- const intentMessage = (0, cryptography_1.messageWithIntent)("TransactionData", builtTransaction);
28
- const hasher = (0, blake2b_1.default)(32);
21
+ const intentMessage = messageWithIntent("TransactionData", builtTransaction);
22
+ const hasher = blake2b(32);
29
23
  hasher.update(intentMessage);
30
24
  const hash = hasher.digest("hex");
31
25
  return `0x${hash}`;
32
26
  });
33
- exports.getLedgerHash = getLedgerHash;
package/lib/msafe.js CHANGED
@@ -1,15 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMsafeAppStoreUrl = exports.getMsafeBaseUrl = exports.isInMsafeApp = void 0;
4
- const isInMsafeApp = () => {
1
+ export const isInMsafeApp = () => {
5
2
  var _a, _b;
6
3
  return typeof window !== "undefined" &&
7
4
  ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.ancestorOrigins) &&
8
5
  Array.from(window.location.ancestorOrigins).length > 0 &&
9
6
  ((_b = Array.from(window.location.ancestorOrigins)[0]) === null || _b === void 0 ? void 0 : _b.includes("m-safe.io"));
10
7
  };
11
- exports.isInMsafeApp = isInMsafeApp;
12
- const getMsafeBaseUrl = () => Array.from(window.location.ancestorOrigins)[0];
13
- exports.getMsafeBaseUrl = getMsafeBaseUrl;
14
- const getMsafeAppStoreUrl = (appName) => `${(0, exports.getMsafeBaseUrl)()}/store/${appName}`;
15
- exports.getMsafeAppStoreUrl = getMsafeAppStoreUrl;
8
+ export const getMsafeBaseUrl = () => Array.from(window.location.ancestorOrigins)[0];
9
+ export const getMsafeAppStoreUrl = (appName) => `${getMsafeBaseUrl()}/store/${appName}`;
@@ -1,10 +1,19 @@
1
- import { CoinStruct, SuiClient, SuiObjectDataFilter, SuiObjectResponse, SuiTransactionBlockResponse } from "@mysten/sui/client";
1
+ import { SuiClientTypes } from "@mysten/sui/client";
2
+ import { SuiJsonRpcClient, SuiTransactionBlockResponse } from "@mysten/sui/jsonRpc";
3
+ import { SuiGrpcClient } from "@mysten/sui/grpc";
2
4
  import { Transaction } from "@mysten/sui/transactions";
3
5
  import BigNumber from "bignumber.js";
4
6
  import { Token } from "./coinMetadata";
5
- export declare const getTotalGasFee: (res: SuiTransactionBlockResponse) => BigNumber;
6
- export declare const getBalanceChange: (res: SuiTransactionBlockResponse, address: string, token: Token, multiplier?: -1 | 1) => BigNumber | undefined;
7
- export declare const getAllOwnedObjects: (suiClient: SuiClient, address: string, filter?: SuiObjectDataFilter) => Promise<SuiObjectResponse[]>;
8
- export declare const getAllCoins: (suiClient: SuiClient, address: string, coinType: string) => Promise<CoinStruct[]>;
9
- export declare const getMostRecentAddressTransaction: (suiClient: SuiClient, address: string, direction: "from" | "to") => Promise<SuiTransactionBlockResponse | undefined>;
10
- export declare const mergeAllCoins: (coinType: string, transaction: Transaction, allCoins: CoinStruct[]) => CoinStruct;
7
+ export declare const getTotalGasFee: (res: SuiClientTypes.TransactionResult<{
8
+ effects: true;
9
+ }>) => BigNumber;
10
+ export declare const getBalanceChange: (res: SuiClientTypes.TransactionResult<{
11
+ balanceChanges: true;
12
+ effects: true;
13
+ }>, address: string, token: Token, multiplier?: -1 | 1) => BigNumber | undefined;
14
+ export declare const getAllOwnedObjects: (suiClient: SuiGrpcClient, address: string, limit?: number, type?: string) => Promise<SuiClientTypes.Object<{
15
+ content: true;
16
+ }>[]>;
17
+ export declare const getAllCoins: (suiClient: SuiGrpcClient, address: string, coinType: string) => Promise<SuiClientTypes.Coin[]>;
18
+ export declare const getMostRecentAddressTransaction: (suiJsonRpcClient: SuiJsonRpcClient, address: string, direction: "from" | "to") => Promise<SuiTransactionBlockResponse | undefined>;
19
+ export declare const mergeAllCoins: (coinType: string, transaction: Transaction, allCoins: SuiClientTypes.Coin[]) => SuiClientTypes.Coin;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,75 +7,68 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ import { SUI_DECIMALS, normalizeStructTag } from "@mysten/sui/utils";
11
+ import BigNumber from "bignumber.js";
12
+ import { isSui } from "./coinType";
13
+ export const getTotalGasFee = (res) => {
14
+ var _a;
15
+ return ((_a = res.Transaction) === null || _a === void 0 ? void 0 : _a.effects)
16
+ ? new BigNumber(+res.Transaction.effects.gasUsed.computationCost +
17
+ +res.Transaction.effects.gasUsed.storageCost -
18
+ +res.Transaction.effects.gasUsed.storageRebate).div(10 ** SUI_DECIMALS)
19
+ : new BigNumber(0);
13
20
  };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.mergeAllCoins = exports.getMostRecentAddressTransaction = exports.getAllCoins = exports.getAllOwnedObjects = exports.getBalanceChange = exports.getTotalGasFee = void 0;
16
- const utils_1 = require("@mysten/sui/utils");
17
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
18
- const coinType_1 = require("./coinType");
19
- const getTotalGasFee = (res) => res.effects
20
- ? new bignumber_js_1.default(+res.effects.gasUsed.computationCost +
21
- +res.effects.gasUsed.storageCost -
22
- +res.effects.gasUsed.storageRebate).div(10 ** utils_1.SUI_DECIMALS)
23
- : new bignumber_js_1.default(0);
24
- exports.getTotalGasFee = getTotalGasFee;
25
- const getBalanceChange = (res, address, token, multiplier = 1) => {
26
- if (!res.balanceChanges)
21
+ export const getBalanceChange = (res, address, token, multiplier = 1) => {
22
+ var _a;
23
+ if (!((_a = res.Transaction) === null || _a === void 0 ? void 0 : _a.balanceChanges))
27
24
  return undefined;
28
- const balanceChanges = res.balanceChanges.filter((bc) => {
29
- var _a;
30
- return (0, utils_1.normalizeStructTag)(bc.coinType) === token.coinType &&
31
- ((_a = bc.owner) === null || _a === void 0 ? void 0 : _a.AddressOwner) === address;
32
- });
25
+ const balanceChanges = res.Transaction.balanceChanges.filter((bc) => normalizeStructTag(bc.coinType) === token.coinType &&
26
+ bc.address === address);
33
27
  if (balanceChanges.length === 0)
34
28
  return undefined;
35
29
  return balanceChanges
36
- .reduce((acc, balanceChange) => acc.plus(new bignumber_js_1.default(+balanceChange.amount)), new bignumber_js_1.default(0))
30
+ .reduce((acc, balanceChange) => acc.plus(new BigNumber(+balanceChange.amount)), new BigNumber(0))
37
31
  .div(10 ** token.decimals)
38
- .plus((0, coinType_1.isSui)(token.coinType) ? (0, exports.getTotalGasFee)(res) : 0)
32
+ .plus(isSui(token.coinType) ? getTotalGasFee(res) : 0)
39
33
  .times(multiplier);
40
34
  };
41
- exports.getBalanceChange = getBalanceChange;
42
- const getAllOwnedObjects = (suiClient, address, filter) => __awaiter(void 0, void 0, void 0, function* () {
35
+ export const getAllOwnedObjects = (suiClient, address, limit, type) => __awaiter(void 0, void 0, void 0, function* () {
43
36
  const allObjs = [];
44
37
  let cursor = null;
45
38
  let hasNextPage = true;
46
39
  while (hasNextPage) {
47
- const objs = yield suiClient.getOwnedObjects({
40
+ const objs = yield suiClient.core.listOwnedObjects({
48
41
  owner: address,
42
+ limit,
49
43
  cursor,
50
- filter,
51
- options: { showContent: true },
44
+ type,
45
+ include: { content: true },
52
46
  });
53
- allObjs.push(...objs.data);
54
- cursor = objs.nextCursor;
47
+ allObjs.push(...objs.objects);
48
+ cursor = objs.cursor;
55
49
  hasNextPage = objs.hasNextPage;
56
50
  }
57
51
  return allObjs;
58
52
  });
59
- exports.getAllOwnedObjects = getAllOwnedObjects;
60
- const getAllCoins = (suiClient, address, coinType) => __awaiter(void 0, void 0, void 0, function* () {
53
+ export const getAllCoins = (suiClient, address, coinType) => __awaiter(void 0, void 0, void 0, function* () {
61
54
  var _a;
62
55
  const allCoins = [];
63
56
  let cursor = undefined;
64
57
  let hasNextPage = true;
65
58
  while (hasNextPage) {
66
- const coins = yield suiClient.getCoins({
59
+ const coins = yield suiClient.core.listCoins({
67
60
  owner: address,
68
61
  coinType,
69
62
  cursor,
70
63
  });
71
- allCoins.push(...coins.data);
72
- cursor = (_a = coins.nextCursor) !== null && _a !== void 0 ? _a : undefined;
64
+ allCoins.push(...coins.objects);
65
+ cursor = (_a = coins.cursor) !== null && _a !== void 0 ? _a : undefined;
73
66
  hasNextPage = coins.hasNextPage;
74
67
  }
75
68
  return allCoins;
76
69
  });
77
- exports.getAllCoins = getAllCoins;
78
- const getMostRecentAddressTransaction = (suiClient, address, direction) => __awaiter(void 0, void 0, void 0, function* () {
79
- const transactions = yield suiClient.queryTransactionBlocks({
70
+ export const getMostRecentAddressTransaction = (suiJsonRpcClient, address, direction) => __awaiter(void 0, void 0, void 0, function* () {
71
+ const transactions = yield suiJsonRpcClient.queryTransactionBlocks({
80
72
  filter: direction === "from" ? { FromAddress: address } : { ToAddress: address },
81
73
  limit: 1,
82
74
  order: "descending",
@@ -86,12 +78,10 @@ const getMostRecentAddressTransaction = (suiClient, address, direction) => __awa
86
78
  });
87
79
  return transactions.data[0];
88
80
  });
89
- exports.getMostRecentAddressTransaction = getMostRecentAddressTransaction;
90
- const mergeAllCoins = (coinType, transaction, allCoins) => {
81
+ export const mergeAllCoins = (coinType, transaction, allCoins) => {
91
82
  const mergeCoin = allCoins[0];
92
- if (allCoins.length > 1 && !(0, coinType_1.isSui)(coinType)) {
93
- transaction.mergeCoins(transaction.object(mergeCoin.coinObjectId), allCoins.map((c) => transaction.object(c.coinObjectId)).slice(1));
83
+ if (allCoins.length > 1 && !isSui(coinType)) {
84
+ transaction.mergeCoins(transaction.object(mergeCoin.objectId), allCoins.map((c) => transaction.object(c.objectId)).slice(1));
94
85
  }
95
86
  return mergeCoin;
96
87
  };
97
- exports.mergeAllCoins = mergeAllCoins;
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@suilend/sui-fe","version":"0.3.52","private":false,"description":"A collection of TypeScript frontend libraries","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./lib/api":"./lib/api.js","./lib/coin":"./lib/coin.js","./lib/coinMetadata":"./lib/coinMetadata.js","./lib/coinType":"./lib/coinType.js","./lib/constants":"./lib/constants.js","./lib/format":"./lib/format.js","./lib":"./lib/index.js","./lib/indexedDB":"./lib/indexedDB.js","./lib/keypair":"./lib/keypair.js","./lib/ledger":"./lib/ledger.js","./lib/msafe":"./lib/msafe.js","./lib/transactions":"./lib/transactions.js"},"types":"./index.js","scripts":{"build":"rm -rf ./dist && bun tsc","eslint":"eslint --fix \"./src/**/*.ts\"","prettier":"prettier --write \"./src/**/*\"","lint":"bun eslint && bun prettier && bun tsc --noEmit","release":"bun run build && bun ts-node ./release.ts && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/suilend/sui-fe.git"},"bugs":{"url":"https://github.com/suilend/sui-fe/issues"},"dependencies":{"@mysten/wallet-standard":"0.19.2","bignumber.js":"^9.1.2","blake2b":"^2.1.4","lodash":"^4.17.21","p-limit":"3.1.0"},"devDependencies":{"@tsconfig/recommended":"^1.0.8","@types/blake2b":"^2.1.3","@types/lodash":"^4.17.13","@types/node":"^22.9.0","@typescript-eslint/eslint-plugin":"^8.14.0","@typescript-eslint/parser":"^8.14.0","eslint":"^9.14.0","eslint-config-prettier":"^9.1.0","eslint-plugin-import":"^2.31.0","eslint-plugin-prettier":"^5.2.1","prettier":"^3.3.3","ts-node":"^10.9.2","typescript":"^5.6.3"},"peerDependencies":{"@mysten/sui":"1.42.0"}}
1
+ {"name":"@suilend/sui-fe","version":"0.4.0","private":false,"description":"A collection of TypeScript frontend libraries","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./lib/constants":"./lib/constants.js","./lib/transactions":"./lib/transactions.js","./lib/format":"./lib/format.js","./lib/ledger":"./lib/ledger.js","./lib/coinMetadata":"./lib/coinMetadata.js","./lib":"./lib/index.js","./lib/indexedDB":"./lib/indexedDB.js","./lib/coinType":"./lib/coinType.js","./lib/coin":"./lib/coin.js","./lib/msafe":"./lib/msafe.js","./lib/keypair":"./lib/keypair.js","./lib/api":"./lib/api.js"},"types":"./index.js","scripts":{"build":"rm -rf ./dist && bun tsc","eslint":"eslint --fix \"./src/**/*.ts\"","prettier":"prettier --write \"./src/**/*\"","lint":"bun eslint && bun prettier && bun tsc --noEmit","release":"bun run build && bun ./release.js && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/suilend/sui-fe.git"},"bugs":{"url":"https://github.com/suilend/sui-fe/issues"},"dependencies":{"@mysten/wallet-standard":"0.20.0","bignumber.js":"^9.1.2","blake2b":"^2.1.4","lodash":"^4.17.21","p-limit":"3.1.0"},"devDependencies":{"@tsconfig/recommended":"^1.0.8","@types/blake2b":"^2.1.3","@types/lodash":"^4.17.13","@types/node":"^22.9.0","@typescript-eslint/eslint-plugin":"^8.14.0","@typescript-eslint/parser":"^8.14.0","eslint":"^9.14.0","eslint-config-prettier":"^9.1.0","eslint-plugin-import":"^2.31.0","eslint-plugin-prettier":"^5.2.1","prettier":"^3.3.3","ts-node":"^10.9.2","typescript":"^5.6.3"},"peerDependencies":{"@mysten/sui":"2.1.0"}}