@triadxyz/triad-protocol 0.2.2-beta → 0.2.5-beta

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/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
2
3
  import { Connection, PublicKey } from '@solana/web3.js';
3
4
  import { TriadProtocol } from './types/triad_protocol';
@@ -13,14 +14,36 @@ export default class TriadProtocolClient {
13
14
  stake: Stake;
14
15
  constructor(connection: Connection, wallet: Wallet);
15
16
  /**
16
- * Get all Users
17
+ * Get User by wallet
18
+ * @param wallet - User wallet
19
+ */
20
+ getUser: (wallet: PublicKey) => Promise<import("./types/stake").UserResponse>;
21
+ /**
22
+ * Get User by wallet
23
+ * @param wallet - User wallet
17
24
  */
18
25
  getUsers: () => Promise<import("./types/stake").UserResponse[]>;
19
26
  /**
20
27
  * Check if user exists
21
28
  * @param username - User name
22
29
  */
23
- hasUser: (username: string) => Promise<boolean>;
30
+ hasUser: (wallet: PublicKey) => Promise<boolean>;
31
+ /**
32
+ * Get Refferal
33
+ * @param name - User name
34
+ */
35
+ getRefferal: (name: string) => Promise<"" | import("@coral-xyz/anchor").ProgramAccount<{
36
+ ts: import("bn.js");
37
+ authority: PublicKey;
38
+ bump: number;
39
+ referral: PublicKey;
40
+ referred: import("bn.js");
41
+ name: string;
42
+ swaps: number;
43
+ swapsMade: number;
44
+ staked: import("bn.js");
45
+ padding: number[];
46
+ }>>;
24
47
  getUserPositions: (userWallet: PublicKey) => Promise<{}[]>;
25
48
  /**
26
49
  * Create User
package/dist/index.js CHANGED
@@ -22,27 +22,48 @@ const stake_1 = __importDefault(require("./stake"));
22
22
  class TriadProtocolClient {
23
23
  constructor(connection, wallet) {
24
24
  /**
25
- * Get all Users
25
+ * Get User by wallet
26
+ * @param wallet - User wallet
27
+ */
28
+ this.getUser = (wallet) => __awaiter(this, void 0, void 0, function* () {
29
+ const UserPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, wallet);
30
+ const response = yield this.program.account.user.fetch(UserPDA);
31
+ return (0, helpers_1.formatUser)(response);
32
+ });
33
+ /**
34
+ * Get User by wallet
35
+ * @param wallet - User wallet
26
36
  */
27
37
  this.getUsers = () => __awaiter(this, void 0, void 0, function* () {
28
38
  const response = yield this.program.account.user.all();
29
- return response
30
- .map((item) => (0, helpers_1.formatUser)(item.account))
31
- .sort((a, b) => b.referred - a.referred);
39
+ return response.map((item) => (0, helpers_1.formatUser)(item));
32
40
  });
33
41
  /**
34
42
  * Check if user exists
35
43
  * @param username - User name
36
44
  */
37
- this.hasUser = (username) => __awaiter(this, void 0, void 0, function* () {
45
+ this.hasUser = (wallet) => __awaiter(this, void 0, void 0, function* () {
38
46
  try {
39
- yield this.program.account.user.fetch((0, helpers_1.getUserAddressSync)(this.program.programId, username));
47
+ yield this.program.account.user.fetch((0, helpers_1.getUserAddressSync)(this.program.programId, wallet));
40
48
  return true;
41
49
  }
42
50
  catch (_a) {
43
51
  return false;
44
52
  }
45
53
  });
54
+ /**
55
+ * Get Refferal
56
+ * @param name - User name
57
+ */
58
+ this.getRefferal = (name) => __awaiter(this, void 0, void 0, function* () {
59
+ try {
60
+ const response = yield this.program.account.user.all();
61
+ return response.find((item) => item.account.name === name);
62
+ }
63
+ catch (_b) {
64
+ return '';
65
+ }
66
+ });
46
67
  this.getUserPositions = (userWallet) => __awaiter(this, void 0, void 0, function* () {
47
68
  const tickers = yield this.ticker.getTickers();
48
69
  const positions = yield Promise.all(tickers
@@ -56,7 +77,7 @@ class TriadProtocolClient {
56
77
  position
57
78
  };
58
79
  }
59
- catch (_b) {
80
+ catch (_c) {
60
81
  return;
61
82
  }
62
83
  return data;
@@ -72,14 +93,13 @@ class TriadProtocolClient {
72
93
  *
73
94
  */
74
95
  this.createUser = ({ wallet, name, referral }, options) => {
75
- const referralPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, referral);
76
96
  const method = this.program.methods
77
97
  .createUser({
78
98
  name
79
99
  })
80
100
  .accounts({
81
101
  signer: wallet,
82
- referral: referralPDA
102
+ referral
83
103
  });
84
104
  if (options === null || options === void 0 ? void 0 : options.microLamports) {
85
105
  method.postInstructions([
package/dist/stake.d.ts CHANGED
@@ -63,7 +63,7 @@ export default class Stake {
63
63
  * @param rarity - NFT rarity
64
64
  *
65
65
  */
66
- stakeToken({ name, wallet, stakeVault, amount, userName }: StakeTokenArgs, options?: RpcOptions): Promise<string>;
66
+ stakeToken({ name, wallet, stakeVault, amount }: StakeTokenArgs, options?: RpcOptions): Promise<string>;
67
67
  /**
68
68
  * Initialize Stake Vault
69
69
  * @param name - The ticker's name
@@ -96,7 +96,7 @@ export default class Stake {
96
96
  * @param stakeVault - Name of the stake vault
97
97
  *
98
98
  */
99
- withdrawStake({ wallet, name, mint, userName, stakeVault }: WithdrawArgs, options?: RpcOptions): Promise<string>;
99
+ withdrawStake({ wallet, name, mint, stakeVault }: WithdrawArgs, options?: RpcOptions): Promise<string>;
100
100
  /**
101
101
  * Update Stake Vault Status
102
102
  * @param wallet - User wallet
package/dist/stake.js CHANGED
@@ -160,11 +160,11 @@ class Stake {
160
160
  * @param rarity - NFT rarity
161
161
  *
162
162
  */
163
- stakeToken({ name, wallet, stakeVault, amount, userName }, options) {
163
+ stakeToken({ name, wallet, stakeVault, amount }, options) {
164
164
  return __awaiter(this, void 0, void 0, function* () {
165
165
  const ttriad = new web3_js_1.PublicKey(constants_1.TTRIAD_MINT);
166
166
  const FromAta = (0, helpers_1.getATASync)(wallet, ttriad);
167
- const userPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, userName);
167
+ const userPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, wallet);
168
168
  const method = this.program.methods
169
169
  .stakeToken({
170
170
  name,
@@ -281,10 +281,10 @@ class Stake {
281
281
  * @param stakeVault - Name of the stake vault
282
282
  *
283
283
  */
284
- withdrawStake({ wallet, name, mint, userName, stakeVault }, options) {
284
+ withdrawStake({ wallet, name, mint, stakeVault }, options) {
285
285
  return __awaiter(this, void 0, void 0, function* () {
286
286
  const stakeVaultPDA = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
287
- const userPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, userName);
287
+ const userPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, wallet);
288
288
  const FromAta = (0, helpers_1.getATASync)(stakeVaultPDA, mint);
289
289
  const stakePDA = (0, helpers_1.getStakeAddressSync)(this.program.programId, wallet, name);
290
290
  const method = this.program.methods.withdrawStake().accounts({
package/dist/test.js CHANGED
@@ -47,6 +47,6 @@ const getUsers = () => __awaiter(void 0, void 0, void 0, function* () {
47
47
  });
48
48
  getUsers();
49
49
  const getReferral = () => __awaiter(void 0, void 0, void 0, function* () {
50
- const response = yield triadProtocol.hasUser('a');
50
+ const response = yield triadProtocol.hasUser(new web3_js_1.PublicKey(''));
51
51
  console.log(response);
52
52
  });
@@ -233,8 +233,8 @@
233
233
  "value": [117, 115, 101, 114]
234
234
  },
235
235
  {
236
- "kind": "arg",
237
- "path": "args.name"
236
+ "kind": "account",
237
+ "path": "signer"
238
238
  }
239
239
  ]
240
240
  }
@@ -6,5 +6,5 @@ export type RpcOptions = {
6
6
  export type CreateUserArgs = {
7
7
  wallet: PublicKey;
8
8
  name: string;
9
- referral?: string;
9
+ referral?: PublicKey;
10
10
  };
@@ -23,7 +23,6 @@ export type StakeTokenArgs = {
23
23
  stakeVault: string;
24
24
  mint: PublicKey;
25
25
  amount: number;
26
- userName: string;
27
26
  };
28
27
  export type InitializeStakeArgs = {
29
28
  name: string;
@@ -48,7 +47,6 @@ export type WithdrawArgs = {
48
47
  name: string;
49
48
  mint: PublicKey;
50
49
  stakeVault: string;
51
- userName: string;
52
50
  };
53
51
  export type UpdateStakeVaultStatusArgs = {
54
52
  wallet: PublicKey;
@@ -314,8 +314,8 @@ export type TriadProtocol = {
314
314
  value: [117, 115, 101, 114];
315
315
  },
316
316
  {
317
- kind: 'arg';
318
- path: 'args.name';
317
+ kind: 'account';
318
+ path: 'signer';
319
319
  }
320
320
  ];
321
321
  };
@@ -11,7 +11,7 @@ export declare const getStakeVaultAddressSync: (programId: PublicKey, vaultName:
11
11
  export declare const getStakeAddressSync: (programId: PublicKey, wallet: PublicKey, name: string) => PublicKey;
12
12
  export declare const getNFTRewardsAddressSync: (programId: PublicKey, stake: PublicKey) => PublicKey;
13
13
  export declare const getATASync: (address: PublicKey, Mint: PublicKey) => PublicKey;
14
- export declare const getUserAddressSync: (programId: PublicKey, name: string) => PublicKey;
14
+ export declare const getUserAddressSync: (programId: PublicKey, wallet: PublicKey) => PublicKey;
15
15
  export declare const formatNumber: (number: bigint | BN, decimals?: number) => number;
16
16
  export declare const formatStakeVault: (stakeVault: any) => StakeVaultResponse;
17
17
  export declare const formatStake: (stake: any) => StakeResponse;
@@ -91,8 +91,8 @@ const getATASync = (address, Mint) => {
91
91
  return ATA;
92
92
  };
93
93
  exports.getATASync = getATASync;
94
- const getUserAddressSync = (programId, name) => {
95
- const [StakePDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('user'), Buffer.from(name)], programId);
94
+ const getUserAddressSync = (programId, wallet) => {
95
+ const [StakePDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('user'), wallet.toBuffer()], programId);
96
96
  return StakePDA;
97
97
  };
98
98
  exports.getUserAddressSync = getUserAddressSync;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "0.2.2-beta",
3
+ "version": "0.2.5-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",