@suilend/sui-fe 0.2.80 → 0.2.81

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/coin.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const BLACKLISTED_WORDS: string[];
package/lib/coin.js ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BLACKLISTED_WORDS = void 0;
4
+ exports.BLACKLISTED_WORDS = [
5
+ // Sui
6
+ "sui",
7
+ "suilend",
8
+ "springsui",
9
+ "steamm",
10
+ "root",
11
+ "rootlet",
12
+ "rootlets",
13
+ "send",
14
+ // Test
15
+ "test",
16
+ "temp",
17
+ "dummy",
18
+ // Brands
19
+ "bnb",
20
+ "bn",
21
+ "okx",
22
+ "coin",
23
+ "coinbase",
24
+ // Inappropriate
25
+ "anal",
26
+ "anus",
27
+ "ass",
28
+ "asshole",
29
+ "bitch",
30
+ "bitching",
31
+ "boob",
32
+ "boobs",
33
+ "butt",
34
+ "butthole",
35
+ "butts",
36
+ "cheat",
37
+ "cheater",
38
+ "cock",
39
+ "cockhead",
40
+ "cocaine",
41
+ "crack",
42
+ "cracker",
43
+ "cunt",
44
+ "cunty",
45
+ "cum",
46
+ "cumshot",
47
+ "death",
48
+ "dead",
49
+ "die",
50
+ "dick",
51
+ "dickhead",
52
+ "drug",
53
+ "drugs",
54
+ "fake",
55
+ "fraud",
56
+ "fuck",
57
+ "fucker",
58
+ "fucking",
59
+ "hack",
60
+ "hacker",
61
+ "hate",
62
+ "heroin",
63
+ "hitler",
64
+ "hax",
65
+ "haxor",
66
+ "jizz",
67
+ "kill",
68
+ "meth",
69
+ "naked",
70
+ "nazi",
71
+ "nude",
72
+ "nudes",
73
+ "pedo",
74
+ "pedophile",
75
+ "penis",
76
+ "pirate",
77
+ "piracy",
78
+ "porn",
79
+ "porno",
80
+ "pussy",
81
+ "pussycat",
82
+ "racism",
83
+ "racist",
84
+ "scam",
85
+ "scammer",
86
+ "sex",
87
+ "sexism",
88
+ "sexist",
89
+ "shit",
90
+ "shitter",
91
+ "shitting",
92
+ "slut",
93
+ "slutty",
94
+ "sperm",
95
+ "steal",
96
+ "terror",
97
+ "terrorist",
98
+ "thief",
99
+ "thieves",
100
+ "tit",
101
+ "tits",
102
+ "vagina",
103
+ "weed",
104
+ "whore",
105
+ "whoring",
106
+ "xxx",
107
+ ];
package/lib/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  export * from "./api";
2
+ export * from "./coin";
2
3
  export * from "./coinMetadata";
3
4
  export * from "./coinType";
4
5
  export * from "./constants";
5
6
  export * from "./format";
6
7
  export * from "./indexedDB";
8
+ export * from "./keypair";
7
9
  export * from "./msafe";
8
10
  export * from "./track";
9
11
  export * from "./transactions";
package/lib/index.js CHANGED
@@ -15,11 +15,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./api"), exports);
18
+ __exportStar(require("./coin"), exports);
18
19
  __exportStar(require("./coinMetadata"), exports);
19
20
  __exportStar(require("./coinType"), exports);
20
21
  __exportStar(require("./constants"), exports);
21
22
  __exportStar(require("./format"), exports);
22
23
  __exportStar(require("./indexedDB"), exports);
24
+ __exportStar(require("./keypair"), exports);
23
25
  __exportStar(require("./msafe"), exports);
24
26
  __exportStar(require("./track"), exports);
25
27
  __exportStar(require("./transactions"), exports);
@@ -0,0 +1,27 @@
1
+ import { SuiClient, SuiTransactionBlockResponse } from "@mysten/sui/client";
2
+ import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
3
+ import { Transaction } from "@mysten/sui/transactions";
4
+ import { SuiSignPersonalMessageMethod, WalletAccount } from "@mysten/wallet-standard";
5
+ import BigNumber from "bignumber.js";
6
+ import { Token } from "./coinMetadata";
7
+ export declare const createKeypair: (account: WalletAccount, signPersonalMessage: SuiSignPersonalMessageMethod) => Promise<{
8
+ keypair: Ed25519Keypair;
9
+ address: string;
10
+ privateKey: string;
11
+ }>;
12
+ export declare const checkIfKeypairCanBeUsed: (currentFlowDigests: string[], keypair: Ed25519Keypair, suiClient: SuiClient) => Promise<void>;
13
+ export declare const keypairSignExecuteAndWaitForTransaction: (transaction: Transaction, keypair: Ed25519Keypair, suiClient: SuiClient) => Promise<SuiTransactionBlockResponse>;
14
+ export type FundKeypairResult = {
15
+ res: SuiTransactionBlockResponse;
16
+ };
17
+ export declare const fundKeypair: (tokens: (Token & {
18
+ amount: BigNumber;
19
+ })[], keypair: Ed25519Keypair, signExecuteAndWaitForTransaction: (transaction: Transaction, options?: {
20
+ auction?: boolean;
21
+ }) => Promise<SuiTransactionBlockResponse>) => Promise<{
22
+ res: SuiTransactionBlockResponse;
23
+ }>;
24
+ export type ReturnAllOwnedObjectsAndSuiToUserResult = {
25
+ res: SuiTransactionBlockResponse;
26
+ };
27
+ export declare const returnAllOwnedObjectsAndSuiToUser: (address: string, keypair: Ed25519Keypair, suiClient: SuiClient) => Promise<ReturnAllOwnedObjectsAndSuiToUserResult>;
package/lib/keypair.js ADDED
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
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.keypairSignExecuteAndWaitForTransaction = exports.checkIfKeypairCanBeUsed = exports.createKeypair = 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 KEYPAIR_SEED_MESSAGE = "send:wallet-connect";
23
+ const createKeypair = (account, signPersonalMessage) => __awaiter(void 0, void 0, void 0, function* () {
24
+ const message = Buffer.from(KEYPAIR_SEED_MESSAGE);
25
+ const { signature } = yield signPersonalMessage({
26
+ message,
27
+ account,
28
+ });
29
+ const signatureBytes = (0, utils_1.fromBase64)(signature);
30
+ const signatureHex = (0, utils_1.toHex)(signatureBytes);
31
+ const keypair = ed25519_1.Ed25519Keypair.deriveKeypairFromSeed(signatureHex);
32
+ const address = keypair.toSuiAddress();
33
+ const privateKey = keypair.getSecretKey();
34
+ console.log("[createKeypair] keypair:", keypair, "address:", address);
35
+ return { keypair, address, privateKey };
36
+ });
37
+ exports.createKeypair = createKeypair;
38
+ const checkIfKeypairCanBeUsed = (currentFlowDigests, keypair, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
39
+ 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; });
40
+ console.log("[checkIfKeypairCanBeUsed] ownedObjectIds:", ownedObjectIds);
41
+ if (ownedObjectIds.length === 0) {
42
+ // Empty wallet
43
+ // CONTINUE
44
+ }
45
+ else {
46
+ const mostRecentFromAddressTransaction = yield (0, transactions_2.getMostRecentFromAddressTransaction)(suiClient, keypair.toSuiAddress());
47
+ console.log("[checkIfKeypairCanBeUsed] mostRecentFromAddressTransaction:", mostRecentFromAddressTransaction, "currentFlowDigests:", currentFlowDigests);
48
+ if (mostRecentFromAddressTransaction === undefined) {
49
+ // Non-empty wallet with no FROM transactions
50
+ // CONTINUE
51
+ }
52
+ else {
53
+ // Non-empty wallet with FROM transactions
54
+ if (currentFlowDigests.includes(mostRecentFromAddressTransaction.digest)) {
55
+ // Retrying current flow
56
+ // CONTINUE
57
+ }
58
+ else {
59
+ // Previous flow
60
+ const timestampMs = mostRecentFromAddressTransaction.timestampMs;
61
+ const isRecent = !!timestampMs && +timestampMs > Date.now() - 1000 * 60 * 2; // Less than 2 minutes ago
62
+ console.log("[checkIfKeypairCanBeUsed] isRecent:", isRecent, timestampMs, Date.now() - 1000 * 60 * 2);
63
+ if (isRecent) {
64
+ // Previous flow may be ongoing
65
+ // STOP
66
+ throw new Error("Please wait for previous flow to complete");
67
+ }
68
+ else {
69
+ // Previous flow stopped before completion
70
+ // CONTINUE
71
+ }
72
+ }
73
+ }
74
+ }
75
+ });
76
+ exports.checkIfKeypairCanBeUsed = checkIfKeypairCanBeUsed;
77
+ const keypairSignExecuteAndWaitForTransaction = (transaction, keypair, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
78
+ var _a, _b;
79
+ // 1) Sign
80
+ const builtTransaction = yield transaction.build({
81
+ client: suiClient,
82
+ });
83
+ const signedTransaction = yield keypair.signTransaction(builtTransaction);
84
+ // 2) Execute
85
+ const res1 = yield suiClient.executeTransactionBlock({
86
+ transactionBlock: signedTransaction.bytes,
87
+ signature: signedTransaction.signature,
88
+ });
89
+ // 3) Wait
90
+ const res2 = yield suiClient.waitForTransaction({
91
+ digest: res1.digest,
92
+ options: {
93
+ showBalanceChanges: true,
94
+ showEffects: true,
95
+ showEvents: true,
96
+ showObjectChanges: true,
97
+ },
98
+ });
99
+ if (((_a = res2.effects) === null || _a === void 0 ? void 0 : _a.status) !== undefined &&
100
+ res2.effects.status.status === "failure")
101
+ throw new Error((_b = res2.effects.status.error) !== null && _b !== void 0 ? _b : "Transaction failed");
102
+ return res2;
103
+ });
104
+ exports.keypairSignExecuteAndWaitForTransaction = keypairSignExecuteAndWaitForTransaction;
105
+ const fundKeypair = (tokens, keypair, signExecuteAndWaitForTransaction) => __awaiter(void 0, void 0, void 0, function* () {
106
+ console.log("[fundKeypair] tokens:", tokens.map((t) => ({
107
+ coinType: t.coinType,
108
+ amount: t.amount.toString(),
109
+ })));
110
+ const fundKeypairTransaction = new transactions_1.Transaction();
111
+ const coinsWithBalance = tokens.map((token) => (0, transactions_1.coinWithBalance)({
112
+ balance: BigInt(token
113
+ .amount.times(10 ** token.decimals)
114
+ .integerValue(bignumber_js_1.default.ROUND_DOWN)
115
+ .toString()),
116
+ type: token.coinType,
117
+ useGasCoin: (0, coinType_1.isSui)(token.coinType),
118
+ })(fundKeypairTransaction));
119
+ fundKeypairTransaction.transferObjects(coinsWithBalance, keypair.toSuiAddress());
120
+ const res = yield signExecuteAndWaitForTransaction(fundKeypairTransaction);
121
+ return { res };
122
+ });
123
+ exports.fundKeypair = fundKeypair;
124
+ const returnAllOwnedObjectsAndSuiToUser = (address, keypair, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
125
+ console.log(`[returnAllOwnedObjectsAndSuiToUser] address: ${address}`);
126
+ const transaction = new transactions_1.Transaction();
127
+ transaction.setSender(keypair.toSuiAddress());
128
+ transaction.transferObjects([transaction.gas], address);
129
+ const ownedObjectIds = (yield (0, transactions_2.getAllOwnedObjects)(suiClient, keypair.toSuiAddress()))
130
+ .filter((obj) => { var _a; return ((_a = obj.data) === null || _a === void 0 ? void 0 : _a.content).type !== "0x2::coin::Coin<0x2::sui::SUI>"; })
131
+ .map((obj) => { var _a; return (_a = obj.data) === null || _a === void 0 ? void 0 : _a.objectId; }); // Assumed to be <512 objects
132
+ transaction.transferObjects(ownedObjectIds, address);
133
+ const res = yield (0, exports.keypairSignExecuteAndWaitForTransaction)(transaction, keypair, suiClient);
134
+ return { res };
135
+ });
136
+ exports.returnAllOwnedObjectsAndSuiToUser = returnAllOwnedObjectsAndSuiToUser;
@@ -1,5 +1,8 @@
1
- import { SuiTransactionBlockResponse } from "@mysten/sui/client";
1
+ import { SuiClient, SuiObjectDataFilter, SuiObjectResponse, SuiTransactionBlockResponse } from "@mysten/sui/client";
2
2
  import BigNumber from "bignumber.js";
3
3
  import { Token } from "./coinMetadata";
4
4
  export declare const getTotalGasFee: (res: SuiTransactionBlockResponse) => BigNumber;
5
5
  export declare const getBalanceChange: (res: SuiTransactionBlockResponse, address: string, token: Token, multiplier?: -1 | 1) => BigNumber | undefined;
6
+ export declare const getAllOwnedObjects: (suiClient: SuiClient, address: string, filter?: SuiObjectDataFilter) => Promise<SuiObjectResponse[]>;
7
+ export declare const getAllCoins: (suiClient: SuiClient, address: string, coinType: string) => Promise<import("@mysten/sui/client").CoinStruct[]>;
8
+ export declare const getMostRecentFromAddressTransaction: (suiClient: SuiClient, address: string) => Promise<SuiTransactionBlockResponse | undefined>;
@@ -1,9 +1,18 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getBalanceChange = exports.getTotalGasFee = void 0;
15
+ exports.getMostRecentFromAddressTransaction = exports.getAllCoins = exports.getAllOwnedObjects = exports.getBalanceChange = exports.getTotalGasFee = void 0;
7
16
  const utils_1 = require("@mysten/sui/utils");
8
17
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
9
18
  const coinType_1 = require("./coinType");
@@ -30,3 +39,60 @@ const getBalanceChange = (res, address, token, multiplier = 1) => {
30
39
  .times(multiplier);
31
40
  };
32
41
  exports.getBalanceChange = getBalanceChange;
42
+ const getAllOwnedObjects = (suiClient, address, filter) => __awaiter(void 0, void 0, void 0, function* () {
43
+ const allObjs = [];
44
+ let cursor = null;
45
+ let hasNextPage = true;
46
+ while (hasNextPage) {
47
+ const objs = yield suiClient.getOwnedObjects({
48
+ owner: address,
49
+ cursor,
50
+ filter,
51
+ options: { showContent: true },
52
+ });
53
+ allObjs.push(...objs.data);
54
+ cursor = objs.nextCursor;
55
+ hasNextPage = objs.hasNextPage;
56
+ }
57
+ return allObjs;
58
+ });
59
+ exports.getAllOwnedObjects = getAllOwnedObjects;
60
+ const getAllCoins = (suiClient, address, coinType) => __awaiter(void 0, void 0, void 0, function* () {
61
+ var _a;
62
+ const allCoins = [];
63
+ let cursor = undefined;
64
+ let hasNextPage = true;
65
+ while (hasNextPage) {
66
+ const coins = yield suiClient.getCoins({
67
+ owner: address,
68
+ coinType,
69
+ cursor,
70
+ });
71
+ allCoins.push(...coins.data);
72
+ cursor = (_a = coins.nextCursor) !== null && _a !== void 0 ? _a : undefined;
73
+ hasNextPage = coins.hasNextPage;
74
+ }
75
+ return allCoins;
76
+ });
77
+ exports.getAllCoins = getAllCoins;
78
+ const getMostRecentFromAddressTransaction = (suiClient, address) => __awaiter(void 0, void 0, void 0, function* () {
79
+ const allTransactions = [];
80
+ let cursor = null;
81
+ let hasNextPage = true;
82
+ while (hasNextPage) {
83
+ const transactions = yield suiClient.queryTransactionBlocks({
84
+ filter: { FromAddress: address },
85
+ cursor,
86
+ limit: 1,
87
+ order: "descending",
88
+ options: {
89
+ showEvents: true,
90
+ },
91
+ });
92
+ allTransactions.push(...transactions.data);
93
+ cursor = transactions.nextCursor;
94
+ hasNextPage = transactions.hasNextPage;
95
+ }
96
+ return allTransactions[0];
97
+ });
98
+ exports.getMostRecentFromAddressTransaction = getMostRecentFromAddressTransaction;
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@suilend/sui-fe","version":"0.2.80","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/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/msafe":"./lib/msafe.js","./lib/track":"./lib/track.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":{"@pythnetwork/pyth-sui-js":"^2.1.0","bignumber.js":"^9.1.2","lodash":"^4.17.21","mixpanel-browser":"^2.56.0","next":"^15.0.3","p-limit":"3.1.0"},"devDependencies":{"@tsconfig/recommended":"^1.0.8","@types/lodash":"^4.17.13","@types/mixpanel-browser":"^2.50.2","@types/node":"^22.9.0","@typescript-eslint/eslint-plugin":"^8.14.0","@typescript-eslint/parser":"^8.14.0","eslint":"^9.14.0","eslint-config-next":"^15.0.3","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.28.2","date-fns":"^4.1.0"}}
1
+ {"name":"@suilend/sui-fe","version":"0.2.81","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/msafe":"./lib/msafe.js","./lib/track":"./lib/track.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.14.7","@pythnetwork/pyth-sui-js":"^2.1.0","bignumber.js":"^9.1.2","lodash":"^4.17.21","mixpanel-browser":"^2.56.0","next":"^15.0.3","p-limit":"3.1.0"},"devDependencies":{"@tsconfig/recommended":"^1.0.8","@types/lodash":"^4.17.13","@types/mixpanel-browser":"^2.50.2","@types/node":"^22.9.0","@typescript-eslint/eslint-plugin":"^8.14.0","@typescript-eslint/parser":"^8.14.0","eslint":"^9.14.0","eslint-config-next":"^15.0.3","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.28.2","date-fns":"^4.1.0"}}