@suilend/sui-fe 2.0.10 → 3.0.1

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.
@@ -1,8 +1,8 @@
1
- import { CoinMetadata } from "@mysten/sui/jsonRpc";
2
- export type Token = CoinMetadata & {
1
+ import { SuiClientTypes } from "@mysten/sui/client";
2
+ export type Token = SuiClientTypes.CoinMetadata & {
3
3
  coinType: string;
4
- raw?: CoinMetadata;
4
+ raw?: SuiClientTypes.CoinMetadata;
5
5
  };
6
- export declare const getToken: (coinType: string, coinMetadata: CoinMetadata) => Token;
6
+ export declare const getToken: (coinType: string, coinMetadata: SuiClientTypes.CoinMetadata) => Token;
7
7
  export declare const getCoinMetadataMap: (uniqueCoinTypes: string[]) => Promise<Record<string, Token>>;
8
8
  export declare const removeCoinMetadataFromIndexedDB: (coinTypes: string[]) => Promise<void>;
@@ -16,6 +16,7 @@ export type Rpc = {
16
16
  name: string;
17
17
  url: string;
18
18
  };
19
+ export declare const RPC_GRAPHQL_URL = "https://sui-mainnet.mystenlabs.com/graphql";
19
20
  export declare const RPCS: Rpc[];
20
21
  export declare enum ExplorerId {
21
22
  SUI_SCAN = "suiScan",
package/lib/constants.js CHANGED
@@ -13,6 +13,7 @@ export var RpcId;
13
13
  RpcId["ALL_THAT_NODE"] = "allThatNode";
14
14
  RpcId["CUSTOM"] = "custom";
15
15
  })(RpcId || (RpcId = {}));
16
+ export const RPC_GRAPHQL_URL = "https://sui-mainnet.mystenlabs.com/graphql";
16
17
  export const RPCS = [
17
18
  {
18
19
  id: RpcId.TRITON_ONE,
package/lib/keypair.d.ts CHANGED
@@ -1,19 +1,34 @@
1
- import { SuiJsonRpcClient, SuiTransactionBlockResponse } from "@mysten/sui/jsonRpc";
1
+ import { SuiGrpcClient } from "@mysten/sui/grpc";
2
+ import { SuiGraphQLClient } from "@mysten/sui/graphql";
3
+ import { SuiClientTypes } from "@mysten/sui/client";
2
4
  import { SignatureWithBytes } from "@mysten/sui/cryptography";
3
5
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
4
6
  import { Transaction } from "@mysten/sui/transactions";
5
7
  import BigNumber from "bignumber.js";
6
8
  import { Token } from "./coinMetadata";
9
+ import { GraphQLTransaction } from "./transactions";
7
10
  export declare class TransactionStatusError extends Error {
8
11
  constructor(message: string);
9
12
  }
10
- export declare const keypairWaitForTransaction: (digest: string, suiClient: SuiJsonRpcClient) => Promise<SuiTransactionBlockResponse>;
11
- export declare const keypairSignExecuteAndWaitForTransaction: (transaction: Transaction, keypair: Ed25519Keypair, suiClient: SuiJsonRpcClient, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiTransactionBlockResponse) => void) => Promise<SuiTransactionBlockResponse>;
13
+ export declare const keypairWaitForTransaction: (digest: string, suiGrpcClient: SuiGrpcClient) => Promise<SuiClientTypes.Transaction<{
14
+ effects: true;
15
+ events: true;
16
+ balanceChanges: true;
17
+ }>>;
18
+ export declare const keypairSignExecuteAndWaitForTransaction: (transaction: Transaction, keypair: Ed25519Keypair, suiGrpcClient: SuiGrpcClient, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiClientTypes.Transaction) => void) => Promise<SuiClientTypes.Transaction<{
19
+ effects: true;
20
+ events: true;
21
+ balanceChanges: true;
22
+ }>>;
12
23
  export type LastSignedTransaction<T> = {
13
24
  signedTransaction: SignatureWithBytes;
14
25
  type: T;
15
26
  };
16
- export declare const checkLastTransactionSignature: <T>(type: T, lastCurrentFlowTransaction: SuiTransactionBlockResponse | undefined, lastSignedTransaction: LastSignedTransaction<T> | undefined, setLastSignedTransaction: (value: LastSignedTransaction<T> | undefined) => void, suiClient: SuiJsonRpcClient, validCallback: (res: SuiTransactionBlockResponse) => Promise<void>, invalidCallback: () => Promise<void>) => Promise<void>;
27
+ export declare const checkLastTransactionSignature: <T>(type: T, lastCurrentFlowTransaction: GraphQLTransaction | undefined, lastSignedTransaction: LastSignedTransaction<T> | undefined, setLastSignedTransaction: (value: LastSignedTransaction<T> | undefined) => void, suiGrpcClient: SuiGrpcClient, validCallback: (res: SuiClientTypes.Transaction<{
28
+ effects: true;
29
+ events: true;
30
+ balanceChanges: true;
31
+ }>) => Promise<void>, invalidCallback: () => Promise<void>) => Promise<void>;
17
32
  export declare const onSign: <T>(type: T, setLastSignedTransaction: (value: LastSignedTransaction<T> | undefined) => void, index?: number) => (signedTransaction: SignatureWithBytes) => void;
18
33
  export declare const KEYPAIR_SEED_MESSAGE = "send:wallet-connect";
19
34
  export declare const createKeypair: (signature: string) => Promise<{
@@ -21,19 +36,35 @@ export declare const createKeypair: (signature: string) => Promise<{
21
36
  address: string;
22
37
  privateKey: string;
23
38
  }>;
24
- export declare const checkIfKeypairCanBeUsed: (lastSignedTransaction: SignatureWithBytes | undefined, currentFlowDigests: string[], keypair: Ed25519Keypair, suiClient: SuiJsonRpcClient) => Promise<{
25
- lastCurrentFlowTransaction: SuiTransactionBlockResponse | undefined;
39
+ export declare const checkIfKeypairCanBeUsed: (lastSignedTransaction: SignatureWithBytes | undefined, currentFlowDigests: string[], keypair: Ed25519Keypair, suiGrpcClient: SuiGrpcClient, graphqlClient: SuiGraphQLClient) => Promise<{
40
+ lastCurrentFlowTransaction: GraphQLTransaction | undefined;
26
41
  }>;
27
42
  export type FundKeypairResult = {
28
- res: SuiTransactionBlockResponse;
43
+ res: SuiClientTypes.Transaction<{
44
+ effects: true;
45
+ events: true;
46
+ balanceChanges: true;
47
+ }>;
29
48
  };
30
49
  export declare const fundKeypair: (tokens: (Token & {
31
50
  amount: BigNumber;
32
- })[], address: string, keypair: Ed25519Keypair, suiClient: SuiJsonRpcClient, signExecuteAndWaitForTransaction: (transaction: Transaction, onSetGasBudget?: (transaction: Transaction) => void, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiTransactionBlockResponse) => void) => Promise<SuiTransactionBlockResponse>, // From WalletContext
33
- onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiTransactionBlockResponse) => void) => Promise<{
34
- res: SuiTransactionBlockResponse;
51
+ })[], address: string, keypair: Ed25519Keypair, suiGrpcClient: SuiGrpcClient, signExecuteAndWaitForTransaction: (transaction: Transaction, onSetGasBudget?: (transaction: Transaction) => void, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiClientTypes.Transaction) => void) => Promise<SuiClientTypes.Transaction<{
52
+ effects: true;
53
+ events: true;
54
+ balanceChanges: true;
55
+ }>>, // From WalletContext
56
+ onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiClientTypes.Transaction) => void) => Promise<{
57
+ res: SuiClientTypes.Transaction<{
58
+ effects: true;
59
+ events: true;
60
+ balanceChanges: true;
61
+ }>;
35
62
  }>;
36
63
  export type ReturnAllOwnedObjectsAndSuiToUserResult = {
37
- res: SuiTransactionBlockResponse;
64
+ res: SuiClientTypes.Transaction<{
65
+ effects: true;
66
+ events: true;
67
+ balanceChanges: true;
68
+ }>;
38
69
  };
39
- export declare const returnAllOwnedObjectsAndSuiToUser: (address: string, keypair: Ed25519Keypair, suiClient: SuiJsonRpcClient, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiTransactionBlockResponse) => void) => Promise<ReturnAllOwnedObjectsAndSuiToUserResult>;
70
+ export declare const returnAllOwnedObjectsAndSuiToUser: (address: string, keypair: Ed25519Keypair, suiGrpcClient: SuiGrpcClient, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiClientTypes.Transaction) => void) => Promise<ReturnAllOwnedObjectsAndSuiToUserResult>;
package/lib/keypair.js CHANGED
@@ -21,51 +21,56 @@ export class TransactionStatusError extends Error {
21
21
  this.name = "TransactionStatusError";
22
22
  }
23
23
  }
24
- export const keypairWaitForTransaction = (digest, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
25
- var _a, _b;
26
- const res = yield suiClient.waitForTransaction({
24
+ export const keypairWaitForTransaction = (digest, suiGrpcClient) => __awaiter(void 0, void 0, void 0, function* () {
25
+ var _a, _b, _c;
26
+ const result = yield suiGrpcClient.waitForTransaction({
27
27
  digest,
28
- options: {
29
- showBalanceChanges: true,
30
- showEffects: true,
31
- showEvents: true,
32
- showObjectChanges: true,
28
+ include: {
29
+ effects: true,
30
+ events: true,
31
+ balanceChanges: true,
33
32
  },
34
33
  });
35
- if (((_a = res.effects) === null || _a === void 0 ? void 0 : _a.status) !== undefined &&
36
- res.effects.status.status === "failure")
37
- throw new TransactionStatusError((_b = res.effects.status.error) !== null && _b !== void 0 ? _b : "Transaction failed");
38
- return res;
34
+ const tx = (_a = result.Transaction) !== null && _a !== void 0 ? _a : result.FailedTransaction;
35
+ if (!tx)
36
+ throw new TransactionStatusError("Transaction not found");
37
+ if (!tx.status.success)
38
+ throw new TransactionStatusError((_c = (_b = tx.status.error) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : "Transaction failed");
39
+ return tx;
39
40
  });
40
- export const keypairSignExecuteAndWaitForTransaction = (transaction, keypair, suiClient, onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
41
+ export const keypairSignExecuteAndWaitForTransaction = (transaction, keypair, suiGrpcClient, onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
42
+ var _a;
41
43
  // 1) Sign
42
44
  const builtTransaction = yield transaction.build({
43
- client: suiClient,
45
+ client: suiGrpcClient,
44
46
  });
45
47
  const signedTransaction = yield keypair.signTransaction(builtTransaction);
46
48
  onSign === null || onSign === void 0 ? void 0 : onSign(signedTransaction);
47
49
  // 2) Execute
48
- const res1 = yield suiClient.executeTransactionBlock({
49
- transactionBlock: signedTransaction.bytes,
50
- signature: signedTransaction.signature,
50
+ const execResult = yield suiGrpcClient.executeTransaction({
51
+ transaction: fromBase64(signedTransaction.bytes),
52
+ signatures: [signedTransaction.signature],
51
53
  });
52
- onExecute === null || onExecute === void 0 ? void 0 : onExecute(res1);
54
+ const execTx = (_a = execResult.Transaction) !== null && _a !== void 0 ? _a : execResult.FailedTransaction;
55
+ if (!execTx)
56
+ throw new TransactionStatusError("Transaction not found");
57
+ onExecute === null || onExecute === void 0 ? void 0 : onExecute(execTx);
53
58
  // 3) Wait
54
- const res2 = yield keypairWaitForTransaction(res1.digest, suiClient);
55
- return res2;
59
+ const tx = yield keypairWaitForTransaction(execTx.digest, suiGrpcClient);
60
+ return tx;
56
61
  });
57
- export const checkLastTransactionSignature = (type, lastCurrentFlowTransaction, lastSignedTransaction, setLastSignedTransaction, suiClient, validCallback, invalidCallback) => __awaiter(void 0, void 0, void 0, function* () {
58
- var _a, _b;
62
+ export const checkLastTransactionSignature = (type, lastCurrentFlowTransaction, lastSignedTransaction, setLastSignedTransaction, suiGrpcClient, validCallback, invalidCallback) => __awaiter(void 0, void 0, void 0, function* () {
63
+ var _a;
59
64
  console.log("[checkLastTransactionSignature]", {
60
65
  type,
61
66
  lastCurrentFlowTransaction,
62
67
  lastSignedTransaction,
63
68
  });
64
69
  if ((lastSignedTransaction === null || lastSignedTransaction === void 0 ? void 0 : lastSignedTransaction.type) === type &&
65
- ((_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)) {
70
+ ((_a = lastCurrentFlowTransaction === null || lastCurrentFlowTransaction === void 0 ? void 0 : lastCurrentFlowTransaction.signatures) !== null && _a !== void 0 ? _a : []).includes(lastSignedTransaction.signedTransaction.signature)) {
66
71
  console.log("[checkLastTransactionSignature] lastSignedTransaction type and signature MATCH");
67
72
  try {
68
- const res = yield 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
73
+ const res = yield keypairWaitForTransaction(lastCurrentFlowTransaction.digest, suiGrpcClient); // Assumed to only throw if the transaction was executed but failed (e.g. insufficient gas), or if the connection was lost
69
74
  yield validCallback(res);
70
75
  setLastSignedTransaction(undefined);
71
76
  }
@@ -116,16 +121,16 @@ export const createKeypair = (signature) => __awaiter(void 0, void 0, void 0, fu
116
121
  return { keypair, address, privateKey };
117
122
  });
118
123
  // CHECK IF KEYPAIR CAN BE USED
119
- export const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigests, keypair, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
120
- var _a, _b;
124
+ export const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigests, keypair, suiGrpcClient, graphqlClient) => __awaiter(void 0, void 0, void 0, function* () {
125
+ var _a;
121
126
  const [mostRecentFromAddressTransaction, mostRecentToAddressTransaction] = yield Promise.all([
122
- getMostRecentAddressTransaction(suiClient, keypair.toSuiAddress(), "from"),
123
- getMostRecentAddressTransaction(suiClient, keypair.toSuiAddress(), "to"),
127
+ getMostRecentAddressTransaction(graphqlClient, keypair.toSuiAddress(), "from"),
128
+ getMostRecentAddressTransaction(graphqlClient, keypair.toSuiAddress(), "to"),
124
129
  ]);
125
130
  const mostRecentFromOrToAddressTransaction = [
126
131
  mostRecentFromAddressTransaction,
127
132
  mostRecentToAddressTransaction,
128
- ].sort((a, b) => { var _a, _b; return +((_a = b === null || b === void 0 ? void 0 : b.timestampMs) !== null && _a !== void 0 ? _a : 0) - +((_b = a === null || a === void 0 ? void 0 : a.timestampMs) !== null && _b !== void 0 ? _b : 0); })[0];
133
+ ].filter(Boolean)[0];
129
134
  console.log("[checkIfKeypairCanBeUsed] mostRecentFromAddressTransaction:", mostRecentFromAddressTransaction, "mostRecentToAddressTransaction:", mostRecentToAddressTransaction, "mostRecentFromOrToAddressTransaction:", mostRecentFromOrToAddressTransaction, "lastSignedTransaction:", lastSignedTransaction, "currentFlowDigests:", currentFlowDigests);
130
135
  // 1) Check if wallet has no TO/FROM transactions
131
136
  if (mostRecentFromOrToAddressTransaction === undefined) {
@@ -136,7 +141,7 @@ export const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigest
136
141
  else {
137
142
  // 2) Check if resuming/retrying current flow
138
143
  if ((lastSignedTransaction !== undefined &&
139
- ((_b = (_a = mostRecentFromOrToAddressTransaction.transaction) === null || _a === void 0 ? void 0 : _a.txSignatures) !== null && _b !== void 0 ? _b : []).includes(lastSignedTransaction.signature)) ||
144
+ ((_a = mostRecentFromOrToAddressTransaction.signatures) !== null && _a !== void 0 ? _a : []).includes(lastSignedTransaction.signature)) ||
140
145
  currentFlowDigests.includes(mostRecentFromOrToAddressTransaction.digest)) {
141
146
  // Resuming/retrying current flow
142
147
  // CONTINUE
@@ -146,7 +151,7 @@ export const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigest
146
151
  }
147
152
  else {
148
153
  // 3) Check if wallet has no owned objects
149
- const ownedObjectIds = (yield getAllOwnedObjects(suiClient, keypair.toSuiAddress())).map((obj) => { var _a; return (_a = obj.data) === null || _a === void 0 ? void 0 : _a.objectId; });
154
+ const ownedObjectIds = (yield getAllOwnedObjects(suiGrpcClient, keypair.toSuiAddress())).map((obj) => obj.objectId);
150
155
  console.log("[checkIfKeypairCanBeUsed] ownedObjectIds:", ownedObjectIds);
151
156
  if (ownedObjectIds.length === 0) {
152
157
  // Previous flow completed
@@ -154,25 +159,13 @@ export const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigest
154
159
  return { lastCurrentFlowTransaction: undefined };
155
160
  }
156
161
  else {
157
- // 4) Check if last transaction from previous flow is recent
158
- const timestampMs = mostRecentFromOrToAddressTransaction.timestampMs;
159
- const isRecent = !!timestampMs && +timestampMs > Date.now() - 1000 * 60 * 2; // Less than 2 minutes ago
160
- console.log("[checkIfKeypairCanBeUsed] isRecent:", isRecent);
161
- if (isRecent) {
162
- // Last transaction from previous flow is recent
163
- // STOP
164
- throw new Error("Please wait for previous flow to complete");
165
- }
166
- else {
167
- // Last transaction from previous flow is NOT recent
168
- // CONTINUE
169
- return { lastCurrentFlowTransaction: undefined };
170
- }
162
+ // CONTINUE (no timestampMs available via GraphQL query; rely on owned objects check)
163
+ return { lastCurrentFlowTransaction: undefined };
171
164
  }
172
165
  }
173
166
  }
174
167
  });
175
- export const fundKeypair = (tokens, address, keypair, suiClient, signExecuteAndWaitForTransaction, // From WalletContext
168
+ export const fundKeypair = (tokens, address, keypair, suiGrpcClient, signExecuteAndWaitForTransaction, // From WalletContext
176
169
  onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
177
170
  const filteredTokens = tokens.filter((t) => t.amount.gt(0));
178
171
  console.log("[fundKeypair] tokens:", tokens.map((t) => ({
@@ -182,7 +175,7 @@ onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
182
175
  coinType: t.coinType,
183
176
  amount: t.amount.toString(),
184
177
  })));
185
- const allCoins = yield Promise.all(filteredTokens.map((token) => getAllCoins(suiClient, address, token.coinType)));
178
+ const allCoins = yield Promise.all(filteredTokens.map((token) => getAllCoins(suiGrpcClient, address, token.coinType)));
186
179
  const transaction = new Transaction();
187
180
  transaction.setSender(address);
188
181
  const mergeCoins = filteredTokens.map((token, index) => mergeAllCoins(token.coinType, transaction, allCoins[index]));
@@ -191,7 +184,7 @@ onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
191
184
  const token = filteredTokens[i];
192
185
  const [coin] = transaction.splitCoins(isSui(token.coinType)
193
186
  ? transaction.gas
194
- : transaction.object(mergeCoins[i].coinObjectId), [
187
+ : transaction.object(mergeCoins[i].objectId), [
195
188
  BigInt(token
196
189
  .amount.times(10 ** token.decimals)
197
190
  .integerValue(BigNumber.ROUND_DOWN)
@@ -203,17 +196,17 @@ onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
203
196
  const res = yield signExecuteAndWaitForTransaction(transaction, undefined, onSign, onExecute);
204
197
  return { res };
205
198
  });
206
- export const returnAllOwnedObjectsAndSuiToUser = (address, keypair, suiClient, onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
199
+ export const returnAllOwnedObjectsAndSuiToUser = (address, keypair, suiGrpcClient, onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
207
200
  console.log(`[returnAllOwnedObjectsAndSuiToUser] address: ${address}`);
208
201
  const transaction = new Transaction();
209
202
  transaction.setSender(keypair.toSuiAddress());
210
203
  transaction.transferObjects([transaction.gas], address); // Will throw if there is no gas
211
- const ownedObjectIds = (yield getAllOwnedObjects(suiClient, keypair.toSuiAddress()))
212
- .filter((obj) => { var _a; return ((_a = obj.data) === null || _a === void 0 ? void 0 : _a.content).type !== "0x2::coin::Coin<0x2::sui::SUI>"; })
213
- .map((obj) => { var _a; return (_a = obj.data) === null || _a === void 0 ? void 0 : _a.objectId; }); // Assumed to be <512 objects
204
+ const ownedObjectIds = (yield getAllOwnedObjects(suiGrpcClient, keypair.toSuiAddress()))
205
+ .filter((obj) => obj.type !== "0x2::coin::Coin<0x2::sui::SUI>")
206
+ .map((obj) => obj.objectId); // Assumed to be <512 objects
214
207
  console.log(`[returnAllOwnedObjectsAndSuiToUser] ownedObjectIds: ${ownedObjectIds}`);
215
208
  if (ownedObjectIds.length > 0)
216
209
  transaction.transferObjects(ownedObjectIds, address);
217
- const res = yield keypairSignExecuteAndWaitForTransaction(transaction, keypair, suiClient, onSign, onExecute);
210
+ const res = yield keypairSignExecuteAndWaitForTransaction(transaction, keypair, suiGrpcClient, onSign, onExecute);
218
211
  return { res };
219
212
  });
package/lib/ledger.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
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: SuiJsonRpcClient) => Promise<string>;
3
+ export declare const getLedgerHash: (address: string, transaction: Transaction, suiGrpcClient: SuiGrpcClient) => Promise<string>;
package/lib/ledger.js CHANGED
@@ -10,12 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { messageWithIntent } from "@mysten/sui/cryptography";
11
11
  import { Transaction } from "@mysten/sui/transactions";
12
12
  import blake2b from "blake2b";
13
- export const getLedgerHash = (address, transaction, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
13
+ export const getLedgerHash = (address, transaction, suiGrpcClient) => __awaiter(void 0, void 0, void 0, function* () {
14
14
  // Build transaction
15
15
  const _transaction = Transaction.from(transaction);
16
16
  _transaction.setSender(address);
17
17
  const builtTransaction = yield _transaction.build({
18
- client: suiClient,
18
+ client: suiGrpcClient,
19
19
  });
20
20
  // Get hash
21
21
  const intentMessage = messageWithIntent("TransactionData", builtTransaction);
@@ -1,10 +1,30 @@
1
- import { CoinStruct, SuiJsonRpcClient, SuiObjectDataFilter, SuiObjectResponse, SuiTransactionBlockResponse } from "@mysten/sui/jsonRpc";
1
+ import { SuiGrpcClient } from "@mysten/sui/grpc";
2
+ import { SuiGraphQLClient } from "@mysten/sui/graphql";
3
+ import { SuiClientTypes } from "@mysten/sui/client";
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: SuiJsonRpcClient, address: string, filter?: SuiObjectDataFilter) => Promise<SuiObjectResponse[]>;
8
- export declare const getAllCoins: (suiClient: SuiJsonRpcClient, address: string, coinType: string) => Promise<CoinStruct[]>;
9
- export declare const getMostRecentAddressTransaction: (suiClient: SuiJsonRpcClient, address: string, direction: "from" | "to") => Promise<SuiTransactionBlockResponse | undefined>;
10
- export declare const mergeAllCoins: (coinType: string, transaction: Transaction, allCoins: CoinStruct[]) => CoinStruct;
7
+ export type GraphQLTransaction = {
8
+ digest: string;
9
+ expiration?: {
10
+ epochId: number;
11
+ } | null;
12
+ signatures?: string[];
13
+ sender?: {
14
+ address: string;
15
+ };
16
+ };
17
+ export declare const getTotalGasFee: (res: SuiClientTypes.Transaction<{
18
+ effects: true;
19
+ balanceChanges: true;
20
+ }>) => BigNumber;
21
+ export declare const getBalanceChange: (res: SuiClientTypes.Transaction<{
22
+ effects: true;
23
+ balanceChanges: true;
24
+ }>, address: string, token: Token, multiplier?: -1 | 1) => BigNumber | undefined;
25
+ export declare const getAllOwnedObjects: (suiGrpcClient: SuiGrpcClient, address: string, type?: string) => Promise<SuiClientTypes.Object<{
26
+ content: true;
27
+ }>[]>;
28
+ export declare const getAllCoins: (suiGrpcClient: SuiGrpcClient, address: string, coinType: string) => Promise<SuiClientTypes.Coin[]>;
29
+ export declare const getMostRecentAddressTransaction: (graphqlClient: SuiGraphQLClient, address: string, direction: "from" | "to") => Promise<GraphQLTransaction | undefined>;
30
+ export declare const mergeAllCoins: (coinType: string, transaction: Transaction, allCoins: SuiClientTypes.Coin[]) => SuiClientTypes.Coin;
@@ -18,11 +18,8 @@ export const getTotalGasFee = (res) => res.effects
18
18
  export const getBalanceChange = (res, address, token, multiplier = 1) => {
19
19
  if (!res.balanceChanges)
20
20
  return undefined;
21
- const balanceChanges = res.balanceChanges.filter((bc) => {
22
- var _a;
23
- return normalizeStructTag(bc.coinType) === token.coinType &&
24
- ((_a = bc.owner) === null || _a === void 0 ? void 0 : _a.AddressOwner) === address;
25
- });
21
+ const balanceChanges = res.balanceChanges.filter((bc) => normalizeStructTag(bc.coinType) === token.coinType &&
22
+ bc.address === address);
26
23
  if (balanceChanges.length === 0)
27
24
  return undefined;
28
25
  return balanceChanges
@@ -31,55 +28,75 @@ export const getBalanceChange = (res, address, token, multiplier = 1) => {
31
28
  .plus(isSui(token.coinType) ? getTotalGasFee(res) : 0)
32
29
  .times(multiplier);
33
30
  };
34
- export const getAllOwnedObjects = (suiClient, address, filter) => __awaiter(void 0, void 0, void 0, function* () {
31
+ export const getAllOwnedObjects = (suiGrpcClient, address, type) => __awaiter(void 0, void 0, void 0, function* () {
35
32
  const allObjs = [];
36
33
  let cursor = null;
37
34
  let hasNextPage = true;
38
35
  while (hasNextPage) {
39
- const objs = yield suiClient.getOwnedObjects({
36
+ const result = yield suiGrpcClient.listOwnedObjects({
40
37
  owner: address,
41
38
  cursor,
42
- filter,
43
- options: { showContent: true },
39
+ type,
40
+ include: { content: true },
44
41
  });
45
- allObjs.push(...objs.data);
46
- cursor = objs.nextCursor;
47
- hasNextPage = objs.hasNextPage;
42
+ allObjs.push(...result.objects);
43
+ cursor = result.cursor;
44
+ hasNextPage = result.hasNextPage;
48
45
  }
49
46
  return allObjs;
50
47
  });
51
- export const getAllCoins = (suiClient, address, coinType) => __awaiter(void 0, void 0, void 0, function* () {
48
+ export const getAllCoins = (suiGrpcClient, address, coinType) => __awaiter(void 0, void 0, void 0, function* () {
52
49
  var _a;
53
50
  const allCoins = [];
54
51
  let cursor = undefined;
55
52
  let hasNextPage = true;
56
53
  while (hasNextPage) {
57
- const coins = yield suiClient.getCoins({
54
+ const result = yield suiGrpcClient.listCoins({
58
55
  owner: address,
59
56
  coinType,
60
57
  cursor,
61
58
  });
62
- allCoins.push(...coins.data);
63
- cursor = (_a = coins.nextCursor) !== null && _a !== void 0 ? _a : undefined;
64
- hasNextPage = coins.hasNextPage;
59
+ allCoins.push(...result.objects);
60
+ cursor = (_a = result.cursor) !== null && _a !== void 0 ? _a : undefined;
61
+ hasNextPage = result.hasNextPage;
65
62
  }
66
63
  return allCoins;
67
64
  });
68
- export const getMostRecentAddressTransaction = (suiClient, address, direction) => __awaiter(void 0, void 0, void 0, function* () {
69
- const transactions = yield suiClient.queryTransactionBlocks({
70
- filter: direction === "from" ? { FromAddress: address } : { ToAddress: address },
71
- limit: 1,
72
- order: "descending",
73
- options: {
74
- showInput: true,
65
+ const QUERY_TRANSACTIONS = `
66
+ query QueryTransactions($filter: TransactionsFilter, $first: Int, $after: String) {
67
+ transactions(
68
+ first: $first
69
+ after: $after
70
+ filter: $filter
71
+ ) {
72
+ nodes {
73
+ digest
74
+ expiration { epochId }
75
+ signatures
76
+ sender { address }
77
+ }
78
+ }
79
+ }
80
+ `;
81
+ export const getMostRecentAddressTransaction = (graphqlClient, address, direction) => __awaiter(void 0, void 0, void 0, function* () {
82
+ var _a, _b;
83
+ const filter = direction === "from"
84
+ ? { sentAddress: address }
85
+ : { affectedAddress: address };
86
+ const result = yield graphqlClient.query({
87
+ query: QUERY_TRANSACTIONS,
88
+ variables: {
89
+ filter,
90
+ first: 1,
75
91
  },
76
92
  });
77
- return transactions.data[0];
93
+ const data = result.data;
94
+ return (_b = (_a = data === null || data === void 0 ? void 0 : data.transactions) === null || _a === void 0 ? void 0 : _a.nodes) === null || _b === void 0 ? void 0 : _b[0];
78
95
  });
79
96
  export const mergeAllCoins = (coinType, transaction, allCoins) => {
80
97
  const mergeCoin = allCoins[0];
81
98
  if (allCoins.length > 1 && !isSui(coinType)) {
82
- transaction.mergeCoins(transaction.object(mergeCoin.coinObjectId), allCoins.map((c) => transaction.object(c.coinObjectId)).slice(1));
99
+ transaction.mergeCoins(transaction.object(mergeCoin.objectId), allCoins.map((c) => transaction.object(c.objectId)).slice(1));
83
100
  }
84
101
  return mergeCoin;
85
102
  };
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@suilend/sui-fe","version":"2.0.10","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/","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.3.1"}}
1
+ {"name":"@suilend/sui-fe","version":"3.0.1","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/","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.15.0"}}