@suilend/sui-fe 0.4.11 → 2.0.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/index.d.ts CHANGED
@@ -1 +1 @@
1
- export * from "./lib/index";
1
+ export * from "./lib";
package/index.js CHANGED
@@ -1 +1 @@
1
- export * from "./lib/index";
1
+ export * from "./lib";
@@ -1,8 +1,8 @@
1
- import { SuiClientTypes } from "@mysten/sui/client";
2
- export type Token = SuiClientTypes.CoinMetadata & {
1
+ import { CoinMetadata } from "@mysten/sui/jsonRpc";
2
+ export type Token = CoinMetadata & {
3
3
  coinType: string;
4
- raw?: SuiClientTypes.CoinMetadata;
4
+ raw?: CoinMetadata;
5
5
  };
6
- export declare const getToken: (coinType: string, coinMetadata: SuiClientTypes.CoinMetadata) => Token;
6
+ export declare const getToken: (coinType: string, coinMetadata: CoinMetadata) => Token;
7
7
  export declare const getCoinMetadataMap: (uniqueCoinTypes: string[]) => Promise<Record<string, Token>>;
8
8
  export declare const removeCoinMetadataFromIndexedDB: (coinTypes: string[]) => Promise<void>;
package/lib/coinType.js CHANGED
@@ -139,6 +139,7 @@ export const NORMALIZED_STABLECOIN_COINTYPES = [
139
139
  NORMALIZED_mUSD_COINTYPE,
140
140
  NORMALIZED_sdeUSD_COINTYPE,
141
141
  NORMALIZED_USDB_COINTYPE,
142
+ NORMALIZED_suiUSDe_COINTYPE,
142
143
  ];
143
144
  export const NORMALIZED_BTC_COINTYPES = [
144
145
  NORMALIZED_suiWBTC_COINTYPE,
@@ -8,6 +8,7 @@ export declare const MS_PER_YEAR = 31556952000;
8
8
  export declare enum RpcId {
9
9
  TRITON_ONE = "tritonOne",
10
10
  FULL_NODE = "fullNode",
11
+ ALL_THAT_NODE = "allThatNode",
11
12
  CUSTOM = "custom"
12
13
  }
13
14
  export type Rpc = {
package/lib/constants.js CHANGED
@@ -10,19 +10,25 @@ export var RpcId;
10
10
  (function (RpcId) {
11
11
  RpcId["TRITON_ONE"] = "tritonOne";
12
12
  RpcId["FULL_NODE"] = "fullNode";
13
+ RpcId["ALL_THAT_NODE"] = "allThatNode";
13
14
  RpcId["CUSTOM"] = "custom";
14
15
  })(RpcId || (RpcId = {}));
15
16
  export const RPCS = [
16
17
  {
17
18
  id: RpcId.TRITON_ONE,
18
19
  name: "Triton One",
19
- url: `https://solendf-suishar-0c55.mainnet.sui.rpcpool.com:443/${(_a = process.env.NEXT_PUBLIC_SUI_TRITON_ONE_DEV_API_KEY) !== null && _a !== void 0 ? _a : ""}`,
20
+ url: `https://solendf-suishar-0c55.mainnet.sui.rpcpool.com/${(_a = process.env.NEXT_PUBLIC_SUI_TRITON_ONE_DEV_API_KEY) !== null && _a !== void 0 ? _a : ""}`,
20
21
  },
21
22
  {
22
23
  id: RpcId.FULL_NODE,
23
24
  name: "Full Node",
24
25
  url: "https://fullnode.mainnet.sui.io:443",
25
26
  },
27
+ {
28
+ id: RpcId.ALL_THAT_NODE,
29
+ name: "All That Node",
30
+ url: "https://sui-mainnet-rpc.allthatnode.com",
31
+ },
26
32
  {
27
33
  id: RpcId.CUSTOM,
28
34
  name: "Custom",
package/lib/keypair.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { SuiClientTypes } from "@mysten/sui/client";
2
- import { SignatureWithBytes } from "@mysten/sui/cryptography";
3
- import { SuiGrpcClient } from "@mysten/sui/grpc";
4
1
  import { SuiJsonRpcClient, SuiTransactionBlockResponse } from "@mysten/sui/jsonRpc";
2
+ import { SignatureWithBytes } from "@mysten/sui/cryptography";
5
3
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
6
4
  import { Transaction } from "@mysten/sui/transactions";
7
5
  import BigNumber from "bignumber.js";
@@ -9,18 +7,13 @@ import { Token } from "./coinMetadata";
9
7
  export declare class TransactionStatusError extends Error {
10
8
  constructor(message: string);
11
9
  }
12
- export declare const keypairWaitForTransaction: (digest: string, suiClient: SuiGrpcClient) => Promise<SuiClientTypes.TransactionResult<{
13
- balanceChanges: true;
14
- effects: true;
15
- events: true;
16
- objectTypes: true;
17
- }>>;
18
- export declare const keypairSignExecuteAndWaitForTransaction: (transaction: Transaction, keypair: Ed25519Keypair, suiClient: SuiGrpcClient, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiClientTypes.TransactionResult) => void) => Promise<Awaited<ReturnType<typeof keypairWaitForTransaction>>>;
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>;
19
12
  export type LastSignedTransaction<T> = {
20
13
  signedTransaction: SignatureWithBytes;
21
14
  type: T;
22
15
  };
23
- export declare const checkLastTransactionSignature: <T>(type: T, lastCurrentFlowTransaction: SuiClientTypes.TransactionResult | undefined, lastSignedTransaction: LastSignedTransaction<T> | undefined, setLastSignedTransaction: (value: LastSignedTransaction<T> | undefined) => void, suiClient: SuiGrpcClient, validCallback: (res: Awaited<ReturnType<typeof keypairWaitForTransaction>>) => Promise<void>, invalidCallback: () => Promise<void>) => Promise<void>;
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>;
24
17
  export declare const onSign: <T>(type: T, setLastSignedTransaction: (value: LastSignedTransaction<T> | undefined) => void, index?: number) => (signedTransaction: SignatureWithBytes) => void;
25
18
  export declare const KEYPAIR_SEED_MESSAGE = "send:wallet-connect";
26
19
  export declare const createKeypair: (signature: string) => Promise<{
@@ -28,29 +21,21 @@ export declare const createKeypair: (signature: string) => Promise<{
28
21
  address: string;
29
22
  privateKey: string;
30
23
  }>;
31
- export declare const checkIfKeypairCanBeUsed: (lastSignedTransaction: SignatureWithBytes | undefined, currentFlowDigests: string[], keypair: Ed25519Keypair, suiClient: SuiGrpcClient, suiJsonRpcClient: SuiJsonRpcClient) => Promise<{
24
+ export declare const checkIfKeypairCanBeUsed: (lastSignedTransaction: SignatureWithBytes | undefined, currentFlowDigests: string[], keypair: Ed25519Keypair, suiClient: SuiJsonRpcClient) => Promise<{
32
25
  lastCurrentFlowTransaction: SuiTransactionBlockResponse | undefined;
33
26
  }>;
34
27
  export type FundKeypairResult = {
35
- res: SuiClientTypes.TransactionResult<{
36
- balanceChanges: true;
37
- effects: true;
38
- events: true;
39
- objectTypes: true;
40
- }>;
28
+ res: SuiTransactionBlockResponse;
41
29
  };
42
30
  export declare const fundKeypair: (tokens: (Token & {
43
31
  amount: BigNumber;
44
- })[], address: string, keypair: Ed25519Keypair, suiClient: SuiGrpcClient, signExecuteAndWaitForTransaction: (transaction: Transaction, options?: {
32
+ })[], address: string, keypair: Ed25519Keypair, suiClient: SuiJsonRpcClient, signExecuteAndWaitForTransaction: (transaction: Transaction, options?: {
45
33
  auction?: boolean;
46
- }, onSetGasBudget?: (transaction: Transaction) => void, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiClientTypes.TransactionResult) => void) => Promise<SuiClientTypes.TransactionResult<{
47
- balanceChanges: true;
48
- effects: true;
49
- events: true;
50
- objectTypes: true;
51
- }>>, // From WalletContext
52
- onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiClientTypes.TransactionResult) => void) => Promise<FundKeypairResult>;
34
+ }, onSetGasBudget?: (transaction: Transaction) => void, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiTransactionBlockResponse) => void) => Promise<SuiTransactionBlockResponse>, // From WalletContext
35
+ onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiTransactionBlockResponse) => void) => Promise<{
36
+ res: SuiTransactionBlockResponse;
37
+ }>;
53
38
  export type ReturnAllOwnedObjectsAndSuiToUserResult = {
54
- res: Awaited<ReturnType<typeof keypairSignExecuteAndWaitForTransaction>>;
39
+ res: SuiTransactionBlockResponse;
55
40
  };
56
- export declare const returnAllOwnedObjectsAndSuiToUser: (address: string, keypair: Ed25519Keypair, suiClient: SuiGrpcClient, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiClientTypes.TransactionResult) => void) => Promise<ReturnAllOwnedObjectsAndSuiToUserResult>;
41
+ export declare const returnAllOwnedObjectsAndSuiToUser: (address: string, keypair: Ed25519Keypair, suiClient: SuiJsonRpcClient, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiTransactionBlockResponse) => void) => Promise<ReturnAllOwnedObjectsAndSuiToUserResult>;
package/lib/keypair.js CHANGED
@@ -12,8 +12,8 @@ import { Transaction, } from "@mysten/sui/transactions";
12
12
  import { fromBase64, toHex } from "@mysten/sui/utils";
13
13
  import BigNumber from "bignumber.js";
14
14
  import { isSui } from "./coinType";
15
- import { API_URL } from "./constants";
16
15
  import { getAllCoins, getAllOwnedObjects, getMostRecentAddressTransaction, mergeAllCoins, } from "./transactions";
16
+ import { API_URL } from "./constants";
17
17
  // SIGN, EXECUTE, AND WAIT FOR
18
18
  export class TransactionStatusError extends Error {
19
19
  constructor(message) {
@@ -22,23 +22,22 @@ export class TransactionStatusError extends Error {
22
22
  }
23
23
  }
24
24
  export const keypairWaitForTransaction = (digest, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
25
- var _a, _b, _c;
25
+ var _a, _b;
26
26
  const res = yield suiClient.waitForTransaction({
27
27
  digest,
28
- include: {
29
- balanceChanges: true,
30
- effects: true,
31
- events: true,
32
- objectTypes: true,
28
+ options: {
29
+ showBalanceChanges: true,
30
+ showEffects: true,
31
+ showEvents: true,
32
+ showObjectChanges: true,
33
33
  },
34
34
  });
35
- const txResult = (_a = res.Transaction) !== null && _a !== void 0 ? _a : res.FailedTransaction;
36
- if ((txResult === null || txResult === void 0 ? void 0 : txResult.effects) && !txResult.effects.status.success)
37
- throw new TransactionStatusError((_c = (_b = txResult.effects.status.error) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : "Transaction failed");
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
38
  return res;
39
39
  });
40
40
  export const keypairSignExecuteAndWaitForTransaction = (transaction, keypair, suiClient, onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
41
- var _a;
42
41
  // 1) Sign
43
42
  const builtTransaction = yield transaction.build({
44
43
  client: suiClient,
@@ -46,15 +45,13 @@ export const keypairSignExecuteAndWaitForTransaction = (transaction, keypair, su
46
45
  const signedTransaction = yield keypair.signTransaction(builtTransaction);
47
46
  onSign === null || onSign === void 0 ? void 0 : onSign(signedTransaction);
48
47
  // 2) Execute
49
- const res1 = yield suiClient.executeTransaction({
50
- transaction: builtTransaction,
51
- signatures: [signedTransaction.signature],
48
+ const res1 = yield suiClient.executeTransactionBlock({
49
+ transactionBlock: signedTransaction.bytes,
50
+ signature: signedTransaction.signature,
52
51
  });
53
- if (!((_a = res1.Transaction) === null || _a === void 0 ? void 0 : _a.digest))
54
- throw new Error("Failed to get transaction digest");
55
52
  onExecute === null || onExecute === void 0 ? void 0 : onExecute(res1);
56
53
  // 3) Wait
57
- const res2 = yield keypairWaitForTransaction(res1.Transaction.digest, suiClient);
54
+ const res2 = yield keypairWaitForTransaction(res1.digest, suiClient);
58
55
  return res2;
59
56
  });
60
57
  export const checkLastTransactionSignature = (type, lastCurrentFlowTransaction, lastSignedTransaction, setLastSignedTransaction, suiClient, validCallback, invalidCallback) => __awaiter(void 0, void 0, void 0, function* () {
@@ -64,13 +61,11 @@ export const checkLastTransactionSignature = (type, lastCurrentFlowTransaction,
64
61
  lastCurrentFlowTransaction,
65
62
  lastSignedTransaction,
66
63
  });
67
- if (!((_a = lastCurrentFlowTransaction === null || lastCurrentFlowTransaction === void 0 ? void 0 : lastCurrentFlowTransaction.Transaction) === null || _a === void 0 ? void 0 : _a.digest))
68
- throw new Error("lastCurrentFlowTransaction digest is missing");
69
64
  if ((lastSignedTransaction === null || lastSignedTransaction === void 0 ? void 0 : lastSignedTransaction.type) === type &&
70
- ((_b = lastCurrentFlowTransaction.Transaction.signatures) !== null && _b !== void 0 ? _b : []).includes(lastSignedTransaction.signedTransaction.signature)) {
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)) {
71
66
  console.log("[checkLastTransactionSignature] lastSignedTransaction type and signature MATCH");
72
67
  try {
73
- const res = yield keypairWaitForTransaction(lastCurrentFlowTransaction.Transaction.digest, suiClient); // Assumed to only throw if the transaction was executed but failed (e.g. insufficient gas), or if the connection was lost
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
74
69
  yield validCallback(res);
75
70
  setLastSignedTransaction(undefined);
76
71
  }
@@ -121,11 +116,11 @@ export const createKeypair = (signature) => __awaiter(void 0, void 0, void 0, fu
121
116
  return { keypair, address, privateKey };
122
117
  });
123
118
  // CHECK IF KEYPAIR CAN BE USED
124
- export const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigests, keypair, suiClient, suiJsonRpcClient) => __awaiter(void 0, void 0, void 0, function* () {
119
+ export const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigests, keypair, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
125
120
  var _a, _b;
126
121
  const [mostRecentFromAddressTransaction, mostRecentToAddressTransaction] = yield Promise.all([
127
- getMostRecentAddressTransaction(suiJsonRpcClient, keypair.toSuiAddress(), "from"),
128
- getMostRecentAddressTransaction(suiJsonRpcClient, keypair.toSuiAddress(), "to"),
122
+ getMostRecentAddressTransaction(suiClient, keypair.toSuiAddress(), "from"),
123
+ getMostRecentAddressTransaction(suiClient, keypair.toSuiAddress(), "to"),
129
124
  ]);
130
125
  const mostRecentFromOrToAddressTransaction = [
131
126
  mostRecentFromAddressTransaction,
@@ -151,7 +146,7 @@ export const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigest
151
146
  }
152
147
  else {
153
148
  // 3) Check if wallet has no owned objects
154
- const ownedObjectIds = (yield getAllOwnedObjects(suiClient, keypair.toSuiAddress())).map((obj) => obj.objectId);
149
+ const ownedObjectIds = (yield getAllOwnedObjects(suiClient, keypair.toSuiAddress())).map((obj) => { var _a; return (_a = obj.data) === null || _a === void 0 ? void 0 : _a.objectId; });
155
150
  console.log("[checkIfKeypairCanBeUsed] ownedObjectIds:", ownedObjectIds);
156
151
  if (ownedObjectIds.length === 0) {
157
152
  // Previous flow completed
@@ -196,7 +191,7 @@ onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
196
191
  const token = filteredTokens[i];
197
192
  const [coin] = transaction.splitCoins(isSui(token.coinType)
198
193
  ? transaction.gas
199
- : transaction.object(mergeCoins[i].objectId), [
194
+ : transaction.object(mergeCoins[i].coinObjectId), [
200
195
  BigInt(token
201
196
  .amount.times(10 ** token.decimals)
202
197
  .integerValue(BigNumber.ROUND_DOWN)
@@ -214,8 +209,8 @@ export const returnAllOwnedObjectsAndSuiToUser = (address, keypair, suiClient, o
214
209
  transaction.setSender(keypair.toSuiAddress());
215
210
  transaction.transferObjects([transaction.gas], address); // Will throw if there is no gas
216
211
  const ownedObjectIds = (yield getAllOwnedObjects(suiClient, keypair.toSuiAddress()))
217
- .filter((obj) => obj.type !== "0x2::coin::Coin<0x2::sui::SUI>")
218
- .map((obj) => obj.objectId); // Assumed to be <512 objects
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
219
214
  console.log(`[returnAllOwnedObjectsAndSuiToUser] ownedObjectIds: ${ownedObjectIds}`);
220
215
  if (ownedObjectIds.length > 0)
221
216
  transaction.transferObjects(ownedObjectIds, address);
package/lib/ledger.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { SuiGrpcClient } from "@mysten/sui/grpc";
1
+ import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
2
2
  import { Transaction } from "@mysten/sui/transactions";
3
- export declare const getLedgerHash: (address: string, transaction: Transaction, suiClient: SuiGrpcClient) => Promise<string>;
3
+ export declare const getLedgerHash: (address: string, transaction: Transaction, suiClient: SuiJsonRpcClient) => Promise<string>;
@@ -1,19 +1,10 @@
1
- import { SuiClientTypes } from "@mysten/sui/client";
2
- import { SuiGrpcClient } from "@mysten/sui/grpc";
3
- import { SuiJsonRpcClient, SuiTransactionBlockResponse } from "@mysten/sui/jsonRpc";
1
+ import { CoinStruct, SuiJsonRpcClient, SuiObjectDataFilter, SuiObjectResponse, SuiTransactionBlockResponse } from "@mysten/sui/jsonRpc";
4
2
  import { Transaction } from "@mysten/sui/transactions";
5
3
  import BigNumber from "bignumber.js";
6
4
  import { Token } from "./coinMetadata";
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
- json: 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;
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;
@@ -10,20 +10,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { SUI_DECIMALS, normalizeStructTag } from "@mysten/sui/utils";
11
11
  import BigNumber from "bignumber.js";
12
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);
20
- };
13
+ export const getTotalGasFee = (res) => res.effects
14
+ ? new BigNumber(+res.effects.gasUsed.computationCost +
15
+ +res.effects.gasUsed.storageCost -
16
+ +res.effects.gasUsed.storageRebate).div(10 ** SUI_DECIMALS)
17
+ : new BigNumber(0);
21
18
  export const getBalanceChange = (res, address, token, multiplier = 1) => {
22
- var _a;
23
- if (!((_a = res.Transaction) === null || _a === void 0 ? void 0 : _a.balanceChanges))
19
+ if (!res.balanceChanges)
24
20
  return undefined;
25
- const balanceChanges = res.Transaction.balanceChanges.filter((bc) => normalizeStructTag(bc.coinType) === token.coinType &&
26
- bc.address === address);
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
+ });
27
26
  if (balanceChanges.length === 0)
28
27
  return undefined;
29
28
  return balanceChanges
@@ -32,20 +31,19 @@ export const getBalanceChange = (res, address, token, multiplier = 1) => {
32
31
  .plus(isSui(token.coinType) ? getTotalGasFee(res) : 0)
33
32
  .times(multiplier);
34
33
  };
35
- export const getAllOwnedObjects = (suiClient, address, limit, type) => __awaiter(void 0, void 0, void 0, function* () {
34
+ export const getAllOwnedObjects = (suiClient, address, filter) => __awaiter(void 0, void 0, void 0, function* () {
36
35
  const allObjs = [];
37
36
  let cursor = null;
38
37
  let hasNextPage = true;
39
38
  while (hasNextPage) {
40
- const objs = yield suiClient.listOwnedObjects({
39
+ const objs = yield suiClient.getOwnedObjects({
41
40
  owner: address,
42
- limit,
43
41
  cursor,
44
- type,
45
- include: { json: true },
42
+ filter,
43
+ options: { showContent: true },
46
44
  });
47
- allObjs.push(...objs.objects);
48
- cursor = objs.cursor;
45
+ allObjs.push(...objs.data);
46
+ cursor = objs.nextCursor;
49
47
  hasNextPage = objs.hasNextPage;
50
48
  }
51
49
  return allObjs;
@@ -56,19 +54,19 @@ export const getAllCoins = (suiClient, address, coinType) => __awaiter(void 0, v
56
54
  let cursor = undefined;
57
55
  let hasNextPage = true;
58
56
  while (hasNextPage) {
59
- const coins = yield suiClient.listCoins({
57
+ const coins = yield suiClient.getCoins({
60
58
  owner: address,
61
59
  coinType,
62
60
  cursor,
63
61
  });
64
- allCoins.push(...coins.objects);
65
- cursor = (_a = coins.cursor) !== null && _a !== void 0 ? _a : undefined;
62
+ allCoins.push(...coins.data);
63
+ cursor = (_a = coins.nextCursor) !== null && _a !== void 0 ? _a : undefined;
66
64
  hasNextPage = coins.hasNextPage;
67
65
  }
68
66
  return allCoins;
69
67
  });
70
- export const getMostRecentAddressTransaction = (suiJsonRpcClient, address, direction) => __awaiter(void 0, void 0, void 0, function* () {
71
- const transactions = yield suiJsonRpcClient.queryTransactionBlocks({
68
+ export const getMostRecentAddressTransaction = (suiClient, address, direction) => __awaiter(void 0, void 0, void 0, function* () {
69
+ const transactions = yield suiClient.queryTransactionBlocks({
72
70
  filter: direction === "from" ? { FromAddress: address } : { ToAddress: address },
73
71
  limit: 1,
74
72
  order: "descending",
@@ -81,7 +79,7 @@ export const getMostRecentAddressTransaction = (suiJsonRpcClient, address, direc
81
79
  export const mergeAllCoins = (coinType, transaction, allCoins) => {
82
80
  const mergeCoin = allCoins[0];
83
81
  if (allCoins.length > 1 && !isSui(coinType)) {
84
- transaction.mergeCoins(transaction.object(mergeCoin.objectId), allCoins.map((c) => transaction.object(c.objectId)).slice(1));
82
+ transaction.mergeCoins(transaction.object(mergeCoin.coinObjectId), allCoins.map((c) => transaction.object(c.coinObjectId)).slice(1));
85
83
  }
86
84
  return mergeCoin;
87
85
  };
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@suilend/sui-fe","version":"0.4.11","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.3.1"}}
1
+ {"name":"@suilend/sui-fe","version":"2.0.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.3.1"}}