@triadxyz/triad-protocol 0.1.2-alpha.9 → 0.1.3-alpha.1

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
@@ -3,11 +3,13 @@ import { Connection, PublicKey } from '@solana/web3.js';
3
3
  import { TriadProtocol } from './types/triad_protocol';
4
4
  import Ticker from './ticker';
5
5
  import Vault from './vault';
6
+ import Stake from './stake';
6
7
  export default class TriadProtocolClient {
7
8
  program: Program<TriadProtocol>;
8
9
  provider: AnchorProvider;
9
10
  ticker: Ticker;
10
11
  vault: Vault;
12
+ stake: Stake;
11
13
  constructor(connection: Connection, wallet: Wallet);
12
14
  getUserPositions: (userWallet: PublicKey) => Promise<{}[]>;
13
15
  }
package/dist/index.js CHANGED
@@ -13,11 +13,11 @@ 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 triad_protocol_1 = require("./types/triad_protocol");
17
- const constants_1 = require("./utils/constants");
16
+ const idl_triad_protocol_json_1 = __importDefault(require("./types/idl_triad_protocol.json"));
18
17
  const ticker_1 = __importDefault(require("./ticker"));
19
18
  const vault_1 = __importDefault(require("./vault"));
20
19
  const helpers_1 = require("./utils/helpers");
20
+ const stake_1 = __importDefault(require("./stake"));
21
21
  class TriadProtocolClient {
22
22
  constructor(connection, wallet) {
23
23
  this.getUserPositions = (userWallet) => __awaiter(this, void 0, void 0, function* () {
@@ -42,9 +42,10 @@ class TriadProtocolClient {
42
42
  return positions;
43
43
  });
44
44
  this.provider = new anchor_1.AnchorProvider(connection, wallet, anchor_1.AnchorProvider.defaultOptions());
45
- 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);
46
46
  this.ticker = new ticker_1.default(this.program, this.provider);
47
47
  this.vault = new vault_1.default(this.program, this.provider);
48
+ this.stake = new stake_1.default(this.program, this.provider);
48
49
  }
49
50
  }
50
51
  exports.default = TriadProtocolClient;
@@ -0,0 +1,128 @@
1
+ import { AnchorProvider, Program } from '@coral-xyz/anchor';
2
+ import { PublicKey } from '@solana/web3.js';
3
+ import { TriadProtocol } from './types/triad_protocol';
4
+ import BN from 'bn.js';
5
+ export default class Stake {
6
+ program: Program<TriadProtocol>;
7
+ provider: AnchorProvider;
8
+ constructor(program: Program<TriadProtocol>, provider: AnchorProvider);
9
+ /**
10
+ * Get all stakes
11
+ */
12
+ getStakes(): Promise<import("@coral-xyz/anchor").ProgramAccount<{
13
+ bump: number;
14
+ authority: PublicKey;
15
+ initTs: BN;
16
+ isLocked: boolean;
17
+ withdrawTs: BN;
18
+ name: string;
19
+ collections: (({
20
+ undead?: never;
21
+ alligators?: never;
22
+ pyth?: never;
23
+ } & {
24
+ coleta: Record<string, never>;
25
+ }) | ({
26
+ coleta?: never;
27
+ alligators?: never;
28
+ pyth?: never;
29
+ } & {
30
+ undead: Record<string, never>;
31
+ }) | ({
32
+ coleta?: never;
33
+ undead?: never;
34
+ pyth?: never;
35
+ } & {
36
+ alligators: Record<string, never>;
37
+ }) | ({
38
+ coleta?: never;
39
+ undead?: never;
40
+ alligators?: never;
41
+ } & {
42
+ pyth: Record<string, never>;
43
+ }))[];
44
+ rarity: ({
45
+ uncommon?: never;
46
+ rare?: never;
47
+ epic?: never;
48
+ legendary?: never;
49
+ } & {
50
+ common: Record<string, never>;
51
+ }) | ({
52
+ common?: never;
53
+ rare?: never;
54
+ epic?: never;
55
+ legendary?: never;
56
+ } & {
57
+ uncommon: Record<string, never>;
58
+ }) | ({
59
+ common?: never;
60
+ uncommon?: never;
61
+ epic?: never;
62
+ legendary?: never;
63
+ } & {
64
+ rare: Record<string, never>;
65
+ }) | ({
66
+ common?: never;
67
+ uncommon?: never;
68
+ rare?: never;
69
+ legendary?: never;
70
+ } & {
71
+ epic: Record<string, never>;
72
+ }) | ({
73
+ common?: never;
74
+ uncommon?: never;
75
+ rare?: never;
76
+ epic?: never;
77
+ } & {
78
+ legendary: Record<string, never>;
79
+ });
80
+ mint: PublicKey;
81
+ stakeVault: PublicKey;
82
+ }>[]>;
83
+ /**
84
+ * Stake NFT
85
+ * @param name - NFT name
86
+ * @param wallet - User wallet
87
+ * @param mint - NFT mint
88
+ * @param collections - NFT collections
89
+ * @param rarity - NFT rarity
90
+ *
91
+ */
92
+ stake({ name, wallet, mint, collections, rarity }: {
93
+ name: string;
94
+ wallet: PublicKey;
95
+ mint: PublicKey;
96
+ collections: {
97
+ alligators: boolean;
98
+ coleta: boolean;
99
+ undead: boolean;
100
+ pyth: boolean;
101
+ };
102
+ rarity: {
103
+ common: {};
104
+ } | {
105
+ uncommon: {};
106
+ } | {
107
+ rare: {};
108
+ } | {
109
+ epic: {};
110
+ } | {
111
+ legendary: {};
112
+ };
113
+ }): Promise<string>;
114
+ /**
115
+ * Update a ticker's price
116
+ * @param name - The ticker's name
117
+ * @param amount - Reward amount
118
+ * @param slots - Amount available to users joining the vault
119
+ * @param collection - The Collection name
120
+ *
121
+ */
122
+ initializeStakeVault({ name, amount, slots, collection }: {
123
+ name: string;
124
+ amount: BN;
125
+ slots: BN;
126
+ collection: string;
127
+ }): Promise<string>;
128
+ }
package/dist/stake.js ADDED
@@ -0,0 +1,82 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const helpers_1 = require("./utils/helpers");
13
+ class Stake {
14
+ constructor(program, provider) {
15
+ this.provider = provider;
16
+ this.program = program;
17
+ }
18
+ /**
19
+ * Get all stakes
20
+ */
21
+ getStakes() {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ return this.program.account.stake.all();
24
+ });
25
+ }
26
+ /**
27
+ * Stake NFT
28
+ * @param name - NFT name
29
+ * @param wallet - User wallet
30
+ * @param mint - NFT mint
31
+ * @param collections - NFT collections
32
+ * @param rarity - NFT rarity
33
+ *
34
+ */
35
+ stake({ name, wallet, mint, collections, rarity }) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const FromAta = (0, helpers_1.getATASync)(wallet, mint);
38
+ let items = [];
39
+ Object.keys(collections).forEach((key) => {
40
+ if (collections[key]) {
41
+ items.push({ [key]: {} });
42
+ }
43
+ });
44
+ return this.program.methods
45
+ .stake({
46
+ name,
47
+ collections: items,
48
+ collection: 'Triad',
49
+ rarity
50
+ })
51
+ .accounts({
52
+ signer: this.provider.wallet.publicKey,
53
+ fromAta: FromAta
54
+ })
55
+ .rpc();
56
+ });
57
+ }
58
+ /**
59
+ * Update a ticker's price
60
+ * @param name - The ticker's name
61
+ * @param amount - Reward amount
62
+ * @param slots - Amount available to users joining the vault
63
+ * @param collection - The Collection name
64
+ *
65
+ */
66
+ initializeStakeVault({ name, amount, slots, collection }) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ return this.program.methods
69
+ .initializeStakeVault({
70
+ name,
71
+ amount,
72
+ slots,
73
+ collection
74
+ })
75
+ .accounts({
76
+ signer: this.provider.wallet.publicKey
77
+ })
78
+ .rpc();
79
+ });
80
+ }
81
+ }
82
+ exports.default = Stake;
package/dist/test.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" />
2
+ import { Connection, Keypair } from '@solana/web3.js';
3
+ import TriadProtocol from './index';
4
+ import { Wallet } from '@coral-xyz/anchor';
5
+ export default class Test {
6
+ file: Buffer;
7
+ Keypair: Keypair;
8
+ connection: Connection;
9
+ wallet: Wallet;
10
+ triadProtocol: TriadProtocol;
11
+ constructor();
12
+ init: () => Promise<void>;
13
+ initializeStakeVault: () => Promise<void>;
14
+ stakeNFT: () => Promise<void>;
15
+ }
package/dist/test.js ADDED
@@ -0,0 +1,50 @@
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
+ const fs_1 = __importDefault(require("fs"));
16
+ const web3_js_1 = require("@solana/web3.js");
17
+ const index_1 = __importDefault(require("./index"));
18
+ const anchor_1 = require("@coral-xyz/anchor");
19
+ class Test {
20
+ constructor() {
21
+ this.file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/id.json');
22
+ this.Keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(this.file.toString())));
23
+ this.connection = new web3_js_1.Connection('http://127.0.0.1:8899');
24
+ this.wallet = new anchor_1.Wallet(this.Keypair);
25
+ this.triadProtocol = new index_1.default(this.connection, this.wallet);
26
+ this.init = () => __awaiter(this, void 0, void 0, function* () { });
27
+ this.initializeStakeVault = () => __awaiter(this, void 0, void 0, function* () {
28
+ const reponse = yield this.triadProtocol.stake.initializeStakeVault({
29
+ name: 'Rev Share 1',
30
+ collection: 'Triad',
31
+ slots: new anchor_1.BN(1939),
32
+ amount: new anchor_1.BN(1000000000)
33
+ });
34
+ console.log('Initialize Stake Vault:', reponse);
35
+ });
36
+ this.stakeNFT = () => __awaiter(this, void 0, void 0, function* () {
37
+ const reponse = yield this.triadProtocol.stake.stake({
38
+ name: 'Rev Share 1',
39
+ wallet: this.wallet.publicKey,
40
+ collections: { alligators: true, coleta: true, undead: true, pyth: true },
41
+ mint: new web3_js_1.PublicKey('DQ3Uq6GDX6HA99jVBaErtZcvhm1AsCpkB421a2MEDJ7B'),
42
+ rarity: { common: {} }
43
+ });
44
+ console.log('Initialize Stake Vault:', reponse);
45
+ });
46
+ }
47
+ }
48
+ exports.default = Test;
49
+ const test = new Test();
50
+ test.stakeNFT();
package/dist/ticker.js CHANGED
@@ -34,16 +34,10 @@ class Ticker {
34
34
  */
35
35
  createTicker({ name, protocolProgramId, tokenMint }) {
36
36
  return __awaiter(this, void 0, void 0, function* () {
37
- const TickerPDA = (0, helpers_1.getTickerAddressSync)(this.program.programId, name);
38
- const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, TickerPDA);
39
- const TokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
40
37
  return this.program.methods
41
38
  .createTicker({ name, protocolProgramId })
42
39
  .accounts({
43
40
  signer: this.provider.wallet.publicKey,
44
- ticker: TickerPDA,
45
- vault: VaultPDA,
46
- tokenAccount: TokenAccountPDA,
47
41
  payerTokenMint: tokenMint
48
42
  })
49
43
  .rpc();