@sleet-js/fastintear-custom-client-setup-with-other-custom-functions 0.0.2 → 0.0.4

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sleet-js/fastintear-custom-client-setup-with-other-custom-functions",
3
3
  "description": "a custom fastintear near client setup",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "module": "src/index.ts",
6
6
  "homepage": "https://sleet-js.near.page",
7
7
  "type": "module",
@@ -11,6 +11,7 @@
11
11
  "url": "https://github.com/sleet-js/fastintear-custom-client-setup-with-other-custom-functions.git"
12
12
  },
13
13
  "exports": {
14
+ ".": "./src/index.ts",
14
15
  "./button_auth.svelte": "./src/svelte/button_auth.svelte",
15
16
  "./button_network_toggle.svelte": "./src/svelte/button_network_toggle.svelte"
16
17
  },
@@ -21,16 +22,16 @@
21
22
  "access": "public"
22
23
  },
23
24
  "devDependencies": {
24
- "@types/bun": "latest"
25
+ "@types/bun": "^1.3.6"
25
26
  },
26
27
  "peerDependencies": {
27
- "typescript": "^5"
28
+ "typescript": "^5.9.3",
29
+ "svelte": "^5.47.0"
28
30
  },
29
31
  "dependencies": {
30
32
  "@sleet-js/ft-methods-const": "^0.0.5",
31
- "@sleet-js/ref-exchange-methods-const": "^0.0.2",
33
+ "@sleet-js/ref-exchange-methods-const": "^0.0.3",
32
34
  "fastintear": "^0.3.8",
33
- "svelte": "^5.46.1",
34
- "zod": "^4.2.1"
35
+ "zod": "^4.3.5"
35
36
  }
36
37
  }
package/src/index.ts CHANGED
@@ -19,9 +19,17 @@ export {
19
19
  ref_add_simple_pool_function,
20
20
  } from "./ref/ref_functions";
21
21
  // other
22
- export { get_nearClient_accountId } from "./other/accountId"
23
- export { delete_key_fun, get_key_list_fun } from "./other/keys"
24
- export type { ACCESS_KEY_INTERFACE } from "./other/key_types"
22
+ export { get_nearClient_accountId } from "./other/accountId";
23
+ export { delete_key_fun, get_key_list_fun } from "./other/keys";
24
+ export type { ACCESS_KEY_INTERFACE } from "./other/key_types";
25
+ // auth
26
+ export {
27
+ isSignedIn,
28
+ accountId,
29
+ auth_update_authStatus_fun,
30
+ auth_handleLogin,
31
+ auth_handleLogout
32
+ } from "./other/auth_login";
25
33
  // ================================================
26
34
  // ================================================
27
35
  // copyright 2025 by sleet.near
@@ -0,0 +1,31 @@
1
+ import { nearClient } from "../createNearClient";
2
+ // ==============================================
3
+ export let isSignedIn: boolean = false;
4
+ export let accountId: string | null = null;
5
+ // ==============================================
6
+ export async function auth_update_authStatus_fun() {
7
+ const status = nearClient().authStatus();
8
+ isSignedIn = status === "SignedIn";
9
+ accountId = isSignedIn ? nearClient().accountId() : null;
10
+ }
11
+ // ==============================================
12
+ export async function auth_handleLogin() {
13
+ try {
14
+ await nearClient().requestSignIn();
15
+ await auth_update_authStatus_fun();
16
+ } catch (error) {
17
+ console.error("Login failed:", error);
18
+ }
19
+ }
20
+ // ==============================================
21
+ export async function auth_handleLogout() {
22
+ try {
23
+ await nearClient().signOut();
24
+ await auth_update_authStatus_fun();
25
+ } catch (error) {
26
+ console.error("Logout failed:", error);
27
+ }
28
+ }
29
+ // ==============================================
30
+ // ==============================================
31
+ // copyright 2025 by sleet.near
@@ -3,7 +3,11 @@
3
3
  import { nearClient } from "../createNearClient";
4
4
  import { ref_exchange_methods_const } from "@sleet-js/ref-exchange-methods-const";
5
5
  import { ref_contractId_for_network } from "./ref_const";
6
- import type { REF_GET_POOL_TYPE } from "./ref_types";
6
+ import type {
7
+ REF_GET_POOL_TYPE,
8
+ REF_GET_DEPOSITS_TYPE,
9
+ STORAGE_BALANCE_OF_RESPONSE_TYPE,
10
+ } from "./ref_types";
7
11
  import {
8
12
  REF_GET_POOL_TYPE_Z_CONST,
9
13
  REF_GET_POOLS_TYPE_Z_CONST,
@@ -15,10 +19,18 @@ interface ref_args_params_interface {
15
19
  limit: number;
16
20
  fee: number;
17
21
  tokens: string[];
22
+ account_id: string;
23
+ token_id: string;
24
+ amount: string;
25
+ deposit: string;
26
+ token_in: string;
27
+ amount_in: string;
28
+ token_out: string;
29
+ min_amount_out: string;
30
+ referral_id: string;
18
31
  }
19
32
  // ================================================
20
- // get_number_of_pools_function
21
- // Fetch the total number of pools
33
+ // ref_get_number_of_pools_function
22
34
  export async function ref_get_number_of_pools_function(): Promise<number> {
23
35
  const result = await nearClient().view({
24
36
  contractId: ref_contractId_for_network(),
@@ -28,7 +40,7 @@ export async function ref_get_number_of_pools_function(): Promise<number> {
28
40
  return result as number;
29
41
  }
30
42
  // ================================================
31
- // get_pool_function
43
+ // ref_get_pool_function
32
44
  export async function ref_get_pool_function(
33
45
  pool_id: ref_args_params_interface["pool_id"],
34
46
  ): Promise<REF_GET_POOL_TYPE> {
@@ -41,7 +53,20 @@ export async function ref_get_pool_function(
41
53
  return REF_GET_POOL_TYPE_Z_CONST.parse(result);
42
54
  }
43
55
  // ================================================
44
- // get_pools_function
56
+ // ref_get_deposits_function
57
+ export async function ref_get_deposits_function(
58
+ accountId: ref_args_params_interface["account_id"],
59
+ ): Promise<REF_GET_DEPOSITS_TYPE> {
60
+ const result = await nearClient().view({
61
+ contractId: ref_contractId_for_network(),
62
+ methodName: ref_exchange_methods_const.get_deposits,
63
+ args: { account_id: accountId },
64
+ });
65
+
66
+ return result as REF_GET_DEPOSITS_TYPE;
67
+ }
68
+ // ================================================
69
+ // ref_get_pools_function
45
70
  export async function ref_get_pools_function(
46
71
  from_index: ref_args_params_interface["from_index"],
47
72
  limit: ref_args_params_interface["limit"],
@@ -55,7 +80,7 @@ export async function ref_get_pools_function(
55
80
  return REF_GET_POOLS_TYPE_Z_CONST.parse(result);
56
81
  }
57
82
  // ================================================
58
- // add_simple_pool_function
83
+ // ref_add_simple_pool_function
59
84
  export async function ref_add_simple_pool_function(
60
85
  fee: ref_args_params_interface["fee"],
61
86
  tokens: ref_args_params_interface["tokens"],
@@ -75,5 +100,117 @@ export async function ref_add_simple_pool_function(
75
100
  return result;
76
101
  }
77
102
  // ================================================
103
+ // ref_withdraw_function
104
+ export async function ref_withdraw_function(
105
+ amount: ref_args_params_interface["amount"],
106
+ token_id: ref_args_params_interface["token_id"],
107
+ ) {
108
+ const result = await nearClient().sendTx({
109
+ receiverId: ref_contractId_for_network(),
110
+ actions: [
111
+ nearClient().actions.functionCall({
112
+ methodName: ref_exchange_methods_const.withdraw,
113
+ args: {
114
+ amount: amount,
115
+ token_id: token_id,
116
+ unregister: false,
117
+ skip_unwrap_near: false,
118
+ },
119
+ gas: "30000000000000", // 30 TGas
120
+ deposit: "1",
121
+ }),
122
+ ],
123
+ });
124
+ console.log(result);
125
+ return result;
126
+ }
127
+ // ================================================
128
+ // ref_get_deposits_function
129
+ export async function ref_storage_balance_of_function(
130
+ accountId: ref_args_params_interface["account_id"],
131
+ ): Promise<STORAGE_BALANCE_OF_RESPONSE_TYPE> {
132
+ const result = await nearClient().view({
133
+ contractId: ref_contractId_for_network(),
134
+ methodName: ref_exchange_methods_const.storage_balance_of,
135
+ args: { account_id: accountId },
136
+ });
137
+
138
+ return result as STORAGE_BALANCE_OF_RESPONSE_TYPE;
139
+ }
140
+ // ================================================
141
+ // ref_storage_deposit_function
142
+ export async function ref_storage_deposit_function(
143
+ deposit: ref_args_params_interface["deposit"],
144
+ ) {
145
+ const result = await nearClient().sendTx({
146
+ receiverId: ref_contractId_for_network(),
147
+ actions: [
148
+ nearClient().actions.functionCall({
149
+ methodName: ref_exchange_methods_const.storage_deposit,
150
+ // args: { },
151
+ gas: "30000000000000", // 30 TGas
152
+ deposit: deposit,
153
+ }),
154
+ ],
155
+ });
156
+ console.log(result);
157
+ return result;
158
+ }
159
+ // ================================================
160
+ // ref_get_return_function
161
+ export async function ref_get_return_function(
162
+ pool_id: ref_args_params_interface["pool_id"],
163
+ token_in: ref_args_params_interface["token_in"],
164
+ amount_in: ref_args_params_interface["amount_in"],
165
+ token_out: ref_args_params_interface["token_out"],
166
+ ): Promise<string> {
167
+ const result = await nearClient().view({
168
+ contractId: ref_contractId_for_network(),
169
+ methodName: ref_exchange_methods_const.get_return,
170
+ args: {
171
+ pool_id: pool_id,
172
+ token_in: token_in,
173
+ amount_in: amount_in,
174
+ token_out: token_out,
175
+ },
176
+ });
177
+ return result as string;
178
+ }
179
+ // ================================================
180
+ // ref_swap_function
181
+ export async function ref_swap_function(
182
+ pool_id: ref_args_params_interface["pool_id"],
183
+ token_in: ref_args_params_interface["token_in"],
184
+ amount_in: ref_args_params_interface["amount_in"],
185
+ token_out: ref_args_params_interface["token_out"],
186
+ min_amount_out: ref_args_params_interface["min_amount_out"],
187
+ referral_id: ref_args_params_interface["referral_id"],
188
+ ) {
189
+ const result = await nearClient().sendTx({
190
+ receiverId: ref_contractId_for_network(),
191
+ actions: [
192
+ nearClient().actions.functionCall({
193
+ methodName: ref_exchange_methods_const.swap,
194
+ args: {
195
+ actions: [
196
+ {
197
+ pool_id: pool_id,
198
+ token_in: token_in,
199
+ amount_in: amount_in,
200
+ token_out: token_out,
201
+ min_amount_out: min_amount_out,
202
+ },
203
+ ],
204
+ referral_id: referral_id,
205
+ },
206
+ gas: "30000000000000", // 30 TGas
207
+ deposit: "1",
208
+ }),
209
+ ],
210
+ });
211
+ console.log(result);
212
+ return result;
213
+ }
214
+ // ================================================
78
215
  // ================================================
79
216
  // copyright 2025 by sleet.near
@@ -20,3 +20,17 @@ export const REF_GET_POOL_TYPE_Z_CONST = z.object({
20
20
  amp: z.number(),
21
21
  }) satisfies z.ZodType<REF_GET_POOL_TYPE>;
22
22
  export const REF_GET_POOLS_TYPE_Z_CONST = z.array(REF_GET_POOL_TYPE_Z_CONST);
23
+ // ==============================================
24
+ // ==============================================
25
+ export interface REF_GET_DEPOSITS_TYPE {
26
+ [key: string]: string;
27
+ }
28
+ // ================================================
29
+ export interface STORAGE_BALANCE_OF_RESPONSE_TYPE {
30
+ total: string;
31
+ available: string;
32
+ }
33
+
34
+ // ================================================
35
+ // ================================================
36
+ // copyright 2025 by sleet.near
@@ -4,37 +4,16 @@
4
4
 
5
5
  <script lang="ts">
6
6
  import { onMount } from "svelte";
7
- import { nearClient } from "../createNearClient";
8
-
9
- let isSignedIn: boolean = false;
10
- let accountId: string | null = null;
11
-
12
- async function updateAuthStatus() {
13
- const status = nearClient().authStatus();
14
- isSignedIn = status === "SignedIn";
15
- accountId = isSignedIn ? nearClient().accountId() : null;
16
- }
17
-
18
- async function handleLogin() {
19
- try {
20
- await nearClient().requestSignIn();
21
- await updateAuthStatus();
22
- } catch (error) {
23
- console.error("Login failed:", error);
24
- }
25
- }
26
-
27
- async function handleLogout() {
28
- try {
29
- await nearClient().signOut();
30
- await updateAuthStatus();
31
- } catch (error) {
32
- console.error("Logout failed:", error);
33
- }
34
- }
35
-
7
+ import {
8
+ isSignedIn,
9
+ accountId,
10
+ auth_update_authStatus_fun,
11
+ auth_handleLogin,
12
+ auth_handleLogout,
13
+ } from "../index";
14
+ // ==================
36
15
  onMount(async () => {
37
- await updateAuthStatus();
16
+ await auth_update_authStatus_fun();
38
17
  });
39
18
  </script>
40
19
 
@@ -44,11 +23,11 @@
44
23
 
45
24
  <!-- AUTH_BUTTON -->
46
25
  {#if isSignedIn}
47
- <button on:click={handleLogout}>
26
+ <button on:click={auth_handleLogout}>
48
27
  LOGOUT {accountId}
49
28
  </button>
50
29
  {:else}
51
- <button on:click={handleLogin}> LOGIN </button>
30
+ <button on:click={auth_handleLogin}> LOGIN </button>
52
31
  {/if}
53
32
 
54
33
  <!-- -->