@triadxyz/triad-protocol 0.1.0-alpha.7 → 0.1.0-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,59 +1,15 @@
1
- /// <reference types="bn.js" />
2
- import { Address, AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
1
+ import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
3
2
  import { Connection, PublicKey } from '@solana/web3.js';
4
3
  import { TriadProtocol } from './types/triad_protocol';
5
4
  import Ticker from './ticker';
6
5
  import Vault from './vault';
6
+ import Stake from './stake';
7
7
  export default class TriadProtocolClient {
8
8
  program: Program<TriadProtocol>;
9
9
  provider: AnchorProvider;
10
10
  ticker: Ticker;
11
11
  vault: Vault;
12
+ stake: Stake;
12
13
  constructor(connection: Connection, wallet: Wallet);
13
- /**
14
- * Get all users
15
- */
16
- getUsers(): Promise<import("@coral-xyz/anchor").ProgramAccount<{
17
- ts: import("bn.js");
18
- name: string;
19
- bump: number;
20
- authority: PublicKey;
21
- referrer: string;
22
- community: string;
23
- netDeposits: import("bn.js");
24
- netWithdraws: import("bn.js");
25
- totalDeposits: import("bn.js");
26
- totalWithdraws: import("bn.js");
27
- lpShares: import("bn.js");
28
- }>[]>;
29
- /**
30
- * Create a new user
31
- * @param name - The ticker's name
32
- * @param referrer - The referrer's public key
33
- * @param community - The community's public key
34
- *
35
- */
36
- createUser({ name, referrer, community }: {
37
- name: string;
38
- referrer: string;
39
- community: string;
40
- }): Promise<string>;
41
- /**
42
- * Get user data
43
- * @param user - The user's public key
44
- *
45
- */
46
- getUserData(user: Address): Promise<{
47
- ts: import("bn.js");
48
- name: string;
49
- bump: number;
50
- authority: PublicKey;
51
- referrer: string;
52
- community: string;
53
- netDeposits: import("bn.js");
54
- netWithdraws: import("bn.js");
55
- totalDeposits: import("bn.js");
56
- totalWithdraws: import("bn.js");
57
- lpShares: import("bn.js");
58
- }>;
14
+ getUserPositions: (userWallet: PublicKey) => Promise<{}[]>;
59
15
  }
package/dist/index.js CHANGED
@@ -13,80 +13,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const anchor_1 = require("@coral-xyz/anchor");
16
- const web3_js_1 = require("@solana/web3.js");
17
- const triad_protocol_1 = require("./types/triad_protocol");
18
- const constants_1 = require("./utils/constants");
16
+ const idl_triad_protocol_json_1 = __importDefault(require("./types/idl_triad_protocol.json"));
19
17
  const ticker_1 = __importDefault(require("./ticker"));
20
- const helpers_1 = require("./utils/helpers");
21
18
  const vault_1 = __importDefault(require("./vault"));
22
- const convertSecretKeyToKeypair_1 = require("./utils/convertSecretKeyToKeypair");
19
+ const helpers_1 = require("./utils/helpers");
20
+ const stake_1 = __importDefault(require("./stake"));
23
21
  class TriadProtocolClient {
24
22
  constructor(connection, wallet) {
23
+ this.getUserPositions = (userWallet) => __awaiter(this, void 0, void 0, function* () {
24
+ const tickers = yield this.ticker.getTickers();
25
+ const positions = yield Promise.all(tickers
26
+ .map((ticker) => __awaiter(this, void 0, void 0, function* () {
27
+ let data = {};
28
+ try {
29
+ const UserPositionPDA = (0, helpers_1.getUserPositionAddressSync)(this.program.programId, userWallet, ticker.publicKey);
30
+ const position = yield this.program.account.userPosition.fetch(UserPositionPDA);
31
+ data = {
32
+ ticker,
33
+ position
34
+ };
35
+ }
36
+ catch (_a) {
37
+ return;
38
+ }
39
+ return data;
40
+ }))
41
+ .filter(Boolean));
42
+ return positions;
43
+ });
25
44
  this.provider = new anchor_1.AnchorProvider(connection, wallet, anchor_1.AnchorProvider.defaultOptions());
26
- this.program = new anchor_1.Program(triad_protocol_1.IDL, constants_1.TRIAD_PROTOCOL_PROGRAM_ID, this.provider);
45
+ this.program = new anchor_1.Program(idl_triad_protocol_json_1.default, this.provider);
27
46
  this.ticker = new ticker_1.default(this.program, this.provider);
28
47
  this.vault = new vault_1.default(this.program, this.provider);
29
- }
30
- /**
31
- * Get all users
32
- */
33
- getUsers() {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- return this.program.account.user.all();
36
- });
37
- }
38
- /**
39
- * Create a new user
40
- * @param name - The ticker's name
41
- * @param referrer - The referrer's public key
42
- * @param community - The community's public key
43
- *
44
- */
45
- createUser({ name, referrer, community }) {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- const UserPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, this.provider.wallet.publicKey);
48
- return this.program.methods
49
- .createUser({
50
- name,
51
- referrer,
52
- community
53
- })
54
- .accounts({
55
- signer: this.provider.wallet.publicKey,
56
- user: UserPDA
57
- })
58
- .rpc();
59
- });
60
- }
61
- /**
62
- * Get user data
63
- * @param user - The user's public key
64
- *
65
- */
66
- getUserData(user) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- try {
69
- return this.program.account.user.fetch(user);
70
- }
71
- catch (error) {
72
- throw new Error('User not found');
73
- }
74
- });
48
+ this.stake = new stake_1.default(this.program, this.provider);
75
49
  }
76
50
  }
77
51
  exports.default = TriadProtocolClient;
78
- const connection = new web3_js_1.Connection('https://devnet.helius-rpc.com/?api-key=3fb2333b-4396-4db0-94c5-663cca63697e', 'confirmed');
79
- const keypair = (0, convertSecretKeyToKeypair_1.convertSecretKeyToKeypair)('43ZaBtQz9KKRw9n731qoxSk18Crp4v11uAre8ucfh8xJMvvkDC7HbsoGGTLFP1Hr1HXLPwKhLaLwetfJ53FQrMC4');
80
- const wallet = new anchor_1.Wallet(keypair);
81
- const triadProtocolClient = new TriadProtocolClient(connection, wallet);
82
- triadProtocolClient.vault
83
- .closePosition({
84
- tickerPDA: new web3_js_1.PublicKey('4gCEAiCm6nHazMsJ1MA1zdAsxLa6kEVkTcaazzpRFMSL'),
85
- amount: '1',
86
- position: 'Long',
87
- mint: new web3_js_1.PublicKey('4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU'),
88
- positionPubkey: new web3_js_1.PublicKey('4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU')
89
- })
90
- .then((a) => {
91
- console.log(a);
92
- });
@@ -0,0 +1,122 @@
1
+ import { AnchorProvider, Program } from '@coral-xyz/anchor';
2
+ import { PublicKey } from '@solana/web3.js';
3
+ import { TriadProtocol } from './types/triad_protocol';
4
+ import { RpcOptions } from './types';
5
+ import { DepositStakeRewardsArgs, InitializeStakeArgs, StakeArgs, RequestWithdrawArgs, WithdrawArgs, StakeResponse, UpdateStakeVaultStatusArgs, UpdateStakeRewardsArgs, ClaimStakeRewardsArgs } from './types/stake';
6
+ export default class Stake {
7
+ program: Program<TriadProtocol>;
8
+ provider: AnchorProvider;
9
+ constructor(program: Program<TriadProtocol>, provider: AnchorProvider);
10
+ /**
11
+ * Get all Stake Vaults
12
+ */
13
+ getStakeVaults(): Promise<import("./types/stake").StakeVaultResponse[]>;
14
+ /**
15
+ * Get Stake Vault by name
16
+ * @param stakeVault - Stake Vault name
17
+ */
18
+ getStakeVaultByName(stakeVault: string): Promise<import("./types/stake").StakeVaultResponse>;
19
+ /**
20
+ * Get all stakes by vault
21
+ * @param stakeVault - Stake Vault name
22
+ *
23
+ */
24
+ getStakes(stakeVault: string): Promise<StakeResponse[]>;
25
+ /**
26
+ * Get Stake by wallet
27
+ * @param wallet - User wallet
28
+ * @param stakeVault - Stake Vault name
29
+ *
30
+ */
31
+ getStakeByWallet(wallet: PublicKey, stakeVault: string): Promise<StakeResponse[]>;
32
+ /**
33
+ * Get Stake Vault Rewards details
34
+ * @param stakeVault - Stake Vault name
35
+ */
36
+ getStakeVaultRewards(stakeVault: string): Promise<{
37
+ amount: number;
38
+ perDay: number;
39
+ perWeek: number;
40
+ perMonth: number;
41
+ period: number;
42
+ days: number[];
43
+ }>;
44
+ /**
45
+ * Get Stakes by day
46
+ * @param stakeVault - Stake Vault name
47
+ * @param day - Day timestamp
48
+ */
49
+ getStakesByDay(stakeVault: string, day: number): Promise<StakeResponse[]>;
50
+ /**
51
+ * Stake NFT
52
+ * @param name - NFT name
53
+ * @param wallet - User wallet
54
+ * @param mint - NFT mint
55
+ * @param collections - NFT collections
56
+ * @param rarity - NFT rarity
57
+ *
58
+ */
59
+ stakeNft({ name, wallet, mint, collections, rarity, stakeVault }: StakeArgs, options?: RpcOptions): Promise<string>;
60
+ /**
61
+ * Initialize Stake Vault
62
+ * @param name - The ticker's name
63
+ * @param slots - Amount available to users joining the vault
64
+ * @param collection - The Collection name
65
+ *
66
+ */
67
+ initializeStakeVault({ name, slots, collection, amount }: InitializeStakeArgs, options?: RpcOptions): Promise<string>;
68
+ /**
69
+ * Deposit Stake Rewards
70
+ * @param wallet - User wallet
71
+ * @param mint - NFT mint
72
+ * @param amount - Reward amount
73
+ *
74
+ */
75
+ depositStakeRewards({ wallet, mint, amount, stakeVault }: DepositStakeRewardsArgs, options?: RpcOptions): Promise<string>;
76
+ /**
77
+ * Request Withdraw
78
+ * @param wallet - User wallet
79
+ * @param nftName - NFT name
80
+ * @param stakeVault - Name of the stake vault
81
+ *
82
+ */
83
+ requestWithdraw({ wallet, nftName, mint, stakeVault }: RequestWithdrawArgs, options?: RpcOptions): Promise<string>;
84
+ /**
85
+ * Withdraw Stake
86
+ * @param wallet - User wallet
87
+ * @param nftName - Stake name
88
+ * @param mint - NFT mint
89
+ * @param stakeVault - Name of the stake vault
90
+ *
91
+ */
92
+ withdrawStake({ wallet, nftName, mint, stakeVault }: WithdrawArgs, options?: RpcOptions): Promise<string>;
93
+ /**
94
+ * Update Stake Vault Status
95
+ * @param wallet - User wallet
96
+ * @param stakeVault - Name of the stake vault
97
+ * @param isLocked - Status of the stake vault
98
+ * @param week - Current week rewards (Starts from 0)
99
+ *
100
+ */
101
+ updateStakeVaultStatus({ wallet, isLocked, week, stakeVault }: UpdateStakeVaultStatusArgs, options?: RpcOptions): Promise<string>;
102
+ /**
103
+ * Update Stake Rewards
104
+ * @param wallet - User wallet
105
+ * @param nft_name - Name of the nft
106
+ * @param apr - APR based in the current day
107
+ * @param day - Day for update rewards (Starts from 0)
108
+ * @param rewards - Rewards for the day
109
+ *
110
+ */
111
+ updateStakeRewards({ wallet, day, items }: UpdateStakeRewardsArgs, options?: RpcOptions): Promise<string>;
112
+ /**
113
+ * Claim Stake Rewards
114
+ * @param wallet - User wallet
115
+ * @param mint - NFT mint
116
+ * @param week - Week rewards
117
+ * @param stakeVault - Name of the stake vault
118
+ * @param nftName - Name of the nft
119
+ *
120
+ */
121
+ claimStakeRewards({ wallet, mint, week, stakeVault, nftName }: ClaimStakeRewardsArgs, options?: RpcOptions): Promise<string>;
122
+ }