@triadxyz/poseidons-protocol 0.1.0 → 0.1.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.
@@ -0,0 +1,61 @@
1
+ /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
2
+ import { PublicKey } from '@solana/web3.js';
3
+ import { Program } from '@coral-xyz/anchor';
4
+ import { PoseidonsProtocol } from './../types/poseidons_protocol';
5
+ import { RpcOptions } from './../types';
6
+ export default class Chest {
7
+ private program;
8
+ private rpcOptions;
9
+ constructor(program: Program<PoseidonsProtocol>, rpcOptions: RpcOptions);
10
+ /**
11
+ * Get all chests
12
+ * @returns The chests
13
+ */
14
+ getAllChest(): Promise<import("./../types").Chest[]>;
15
+ /**
16
+ * Get a chest
17
+ * @param id - The id of the chest
18
+ * @returns The chest
19
+ */
20
+ getChest(id: number): Promise<import("./../types").Chest>;
21
+ /**
22
+ * Create a chest
23
+ * @param id - The id of the chest
24
+ * @param price - The price of the chest
25
+ * @param amount - The amount of the chest
26
+ * @returns The transaction signature or versioned transaction
27
+ */
28
+ createChest({ id, price, amount }: {
29
+ id: number;
30
+ price: number;
31
+ amount: number;
32
+ }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
33
+ /**
34
+ * Place a bid on a chest
35
+ * @param id - The id of the chest
36
+ * @param coins - The coins to bid
37
+ * @returns The transaction signature or versioned transaction
38
+ */
39
+ placeChestBid({ id, coins }: {
40
+ id: number;
41
+ coins: number;
42
+ }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
43
+ /**
44
+ * Add chest winners
45
+ * @param id - The id of the chest
46
+ * @param grandWinner - The grand winner of the chest
47
+ * @param top10 - The top 10 winners of the chest
48
+ * @returns The transaction signature or versioned transaction
49
+ */
50
+ addChestWinners({ id, grandWinner, top10 }: {
51
+ id: number;
52
+ grandWinner: {
53
+ authority: PublicKey;
54
+ amount: number;
55
+ };
56
+ top10: {
57
+ authority: PublicKey;
58
+ amount: number;
59
+ }[];
60
+ }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
61
+ }
@@ -0,0 +1,124 @@
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 anchor_1 = require("@coral-xyz/anchor");
16
+ const sendVersionedTransaction_1 = __importDefault(require("./../utils/sendVersionedTransaction"));
17
+ const pda_1 = require("./../utils/pda");
18
+ const helpers_1 = require("./../utils/helpers");
19
+ class Chest {
20
+ constructor(program, rpcOptions) {
21
+ this.program = program;
22
+ this.rpcOptions = rpcOptions;
23
+ }
24
+ /**
25
+ * Get all chests
26
+ * @returns The chests
27
+ */
28
+ getAllChest() {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const chests = yield this.program.account.chest.all();
31
+ return chests.map((chest) => (0, helpers_1.formatChest)(chest.account, chest.publicKey));
32
+ });
33
+ }
34
+ /**
35
+ * Get a chest
36
+ * @param id - The id of the chest
37
+ * @returns The chest
38
+ */
39
+ getChest(id) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const chestPDA = (0, pda_1.getChestPDA)(id);
42
+ const chest = yield this.program.account.chest.fetch(chestPDA);
43
+ return (0, helpers_1.formatChest)(chest, chestPDA);
44
+ });
45
+ }
46
+ /**
47
+ * Create a chest
48
+ * @param id - The id of the chest
49
+ * @param price - The price of the chest
50
+ * @param amount - The amount of the chest
51
+ * @returns The transaction signature or versioned transaction
52
+ */
53
+ createChest({ id, price, amount }) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const instructions = [
56
+ yield this.program.methods
57
+ .createChest({
58
+ id: new anchor_1.BN(id),
59
+ price: new anchor_1.BN(price),
60
+ amount: new anchor_1.BN(amount)
61
+ })
62
+ .accounts({
63
+ signer: this.program.provider.publicKey
64
+ })
65
+ .instruction()
66
+ ];
67
+ return (0, sendVersionedTransaction_1.default)(this.program, instructions, this.rpcOptions);
68
+ });
69
+ }
70
+ /**
71
+ * Place a bid on a chest
72
+ * @param id - The id of the chest
73
+ * @param coins - The coins to bid
74
+ * @returns The transaction signature or versioned transaction
75
+ */
76
+ placeChestBid({ id, coins }) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const instructions = [
79
+ yield this.program.methods
80
+ .placeChestBid({
81
+ id: new anchor_1.BN(id),
82
+ coins: new anchor_1.BN(coins)
83
+ })
84
+ .accounts({
85
+ signer: this.program.provider.publicKey,
86
+ user: (0, pda_1.getUserPDA)(this.program.provider.publicKey)
87
+ })
88
+ .instruction()
89
+ ];
90
+ return (0, sendVersionedTransaction_1.default)(this.program, instructions, this.rpcOptions);
91
+ });
92
+ }
93
+ /**
94
+ * Add chest winners
95
+ * @param id - The id of the chest
96
+ * @param grandWinner - The grand winner of the chest
97
+ * @param top10 - The top 10 winners of the chest
98
+ * @returns The transaction signature or versioned transaction
99
+ */
100
+ addChestWinners({ id, grandWinner, top10 }) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ const instructions = [
103
+ yield this.program.methods
104
+ .addChestWinners({
105
+ id: new anchor_1.BN(id),
106
+ grandWinner: {
107
+ authority: grandWinner.authority,
108
+ amount: new anchor_1.BN(grandWinner.amount)
109
+ },
110
+ top10: top10.map((top10) => ({
111
+ authority: top10.authority,
112
+ amount: new anchor_1.BN(top10.amount)
113
+ }))
114
+ })
115
+ .accounts({
116
+ signer: this.program.provider.publicKey
117
+ })
118
+ .instruction()
119
+ ];
120
+ return (0, sendVersionedTransaction_1.default)(this.program, instructions, this.rpcOptions);
121
+ });
122
+ }
123
+ }
124
+ exports.default = Chest;
@@ -0,0 +1,10 @@
1
+ import { Program } from '@coral-xyz/anchor';
2
+ import { PoseidonsProtocol } from './../types/poseidons_protocol';
3
+ import { RpcOptions } from './../types';
4
+ import Chest from './chest';
5
+ export default class Game {
6
+ private program;
7
+ private rpcOptions;
8
+ chest: Chest;
9
+ constructor(program: Program<PoseidonsProtocol>, rpcOptions: RpcOptions);
10
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const chest_1 = __importDefault(require("./chest"));
7
+ class Game {
8
+ constructor(program, rpcOptions) {
9
+ this.program = program;
10
+ this.rpcOptions = rpcOptions;
11
+ this.chest = new chest_1.default(this.program, this.rpcOptions);
12
+ }
13
+ }
14
+ exports.default = Game;
package/dist/index.d.ts CHANGED
@@ -3,13 +3,18 @@ import { Connection, PublicKey } from '@solana/web3.js';
3
3
  import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
4
4
  import { PoseidonsProtocol } from './types/poseidons_protocol';
5
5
  import { RpcOptions } from './types';
6
+ import Game from './game';
6
7
  export * from './types';
8
+ export * from './utils/constants';
9
+ export * from './utils/helpers';
10
+ export * from './utils/pda';
7
11
  export default class PoseidonsProtocolClient {
8
12
  private connection;
9
13
  private wallet;
10
14
  private rpcOptions;
11
15
  program: Program<PoseidonsProtocol>;
12
16
  provider: AnchorProvider;
17
+ game: Game;
13
18
  constructor(connection: Connection, wallet: Wallet, rpcOptions: RpcOptions);
14
19
  /**
15
20
  * Get Poseidon Vault
@@ -27,6 +32,11 @@ export default class PoseidonsProtocolClient {
27
32
  * @returns The Poseidon
28
33
  */
29
34
  getPoseidon(mint: PublicKey): Promise<import("./types").Poseidon>;
35
+ /**
36
+ * Get User
37
+ * @returns The User
38
+ */
39
+ getUser(): Promise<import("./types").User>;
30
40
  /**
31
41
  * Add Poseidon vault rewards
32
42
  * @returns The transaction signature or versioned transaction
@@ -48,13 +58,11 @@ export default class PoseidonsProtocolClient {
48
58
  * Add Poseidon rewards
49
59
  * @param mint - The mint of the Poseidon
50
60
  * @param amount - The amount of rewards to add
51
- * @param boost - Whether to boost the Poseidon
52
61
  * @returns The transaction signature or versioned transaction
53
62
  */
54
63
  addPoseidonRewards(poseidons: {
55
64
  mint: PublicKey;
56
65
  amount: number;
57
- power: number;
58
66
  }[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
59
67
  /**
60
68
  * Burn NFT
@@ -63,4 +71,16 @@ export default class PoseidonsProtocolClient {
63
71
  * @returns The transaction signature or versioned transaction
64
72
  */
65
73
  burnNft(mint: PublicKey, burnMint: PublicKey): Promise<string | import("@solana/web3.js").VersionedTransaction>;
74
+ /**
75
+ * Create a user
76
+ * @param refer - The refer of the user
77
+ * @returns The transaction signature or versioned transaction
78
+ */
79
+ createUser(refer: PublicKey): Promise<string | import("@solana/web3.js").VersionedTransaction>;
80
+ /**
81
+ * Withdraw funds
82
+ * @param amount - The amount of funds to withdraw
83
+ * @returns The transaction signature or versioned transaction
84
+ */
85
+ withdrawFunds(amount: number): Promise<string | import("@solana/web3.js").VersionedTransaction>;
66
86
  }
package/dist/index.js CHANGED
@@ -32,7 +32,11 @@ const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersione
32
32
  const pda_1 = require("./utils/pda");
33
33
  const helpers_1 = require("./utils/helpers");
34
34
  const constants_1 = require("./utils/constants");
35
+ const game_1 = __importDefault(require("./game"));
35
36
  __exportStar(require("./types"), exports);
37
+ __exportStar(require("./utils/constants"), exports);
38
+ __exportStar(require("./utils/helpers"), exports);
39
+ __exportStar(require("./utils/pda"), exports);
36
40
  class PoseidonsProtocolClient {
37
41
  constructor(connection, wallet, rpcOptions) {
38
42
  this.connection = connection;
@@ -45,6 +49,7 @@ class PoseidonsProtocolClient {
45
49
  commitment: this.rpcOptions.commitment || 'confirmed'
46
50
  });
47
51
  this.program = new anchor_1.Program(idl_poseidons_protocol_json_1.default, this.provider);
52
+ this.game = new game_1.default(this.program, this.rpcOptions);
48
53
  }
49
54
  /**
50
55
  * Get Poseidon Vault
@@ -78,6 +83,17 @@ class PoseidonsProtocolClient {
78
83
  return (0, helpers_1.formatPoseidon)(poseidon, poseidonPDA);
79
84
  });
80
85
  }
86
+ /**
87
+ * Get User
88
+ * @returns The User
89
+ */
90
+ getUser() {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ const userPDA = (0, pda_1.getUserPDA)(this.program.provider.publicKey);
93
+ const user = yield this.program.account.user.fetch(userPDA);
94
+ return (0, helpers_1.formatUser)(user, userPDA);
95
+ });
96
+ }
81
97
  /**
82
98
  * Add Poseidon vault rewards
83
99
  * @returns The transaction signature or versioned transaction
@@ -138,7 +154,6 @@ class PoseidonsProtocolClient {
138
154
  * Add Poseidon rewards
139
155
  * @param mint - The mint of the Poseidon
140
156
  * @param amount - The amount of rewards to add
141
- * @param boost - Whether to boost the Poseidon
142
157
  * @returns The transaction signature or versioned transaction
143
158
  */
144
159
  addPoseidonRewards(poseidons) {
@@ -146,7 +161,7 @@ class PoseidonsProtocolClient {
146
161
  const ixs = [];
147
162
  for (const poseidon of poseidons) {
148
163
  ixs.push(yield this.program.methods
149
- .addPoseidonRewards(new anchor_1.BN(poseidon.amount * Math.pow(10, 6)), new anchor_1.BN(poseidon.power))
164
+ .addPoseidonRewards(new anchor_1.BN(poseidon.amount * Math.pow(10, 6)))
150
165
  .accounts({
151
166
  signer: this.program.provider.publicKey,
152
167
  poseidon: (0, pda_1.getPoseidonPDA)(poseidon.mint)
@@ -177,5 +192,43 @@ class PoseidonsProtocolClient {
177
192
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
178
193
  });
179
194
  }
195
+ /**
196
+ * Create a user
197
+ * @param refer - The refer of the user
198
+ * @returns The transaction signature or versioned transaction
199
+ */
200
+ createUser(refer) {
201
+ return __awaiter(this, void 0, void 0, function* () {
202
+ const ixs = [
203
+ yield this.program.methods
204
+ .createUser(refer)
205
+ .accounts({
206
+ signer: this.program.provider.publicKey,
207
+ payer: this.rpcOptions.payer
208
+ })
209
+ .instruction()
210
+ ];
211
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
212
+ });
213
+ }
214
+ /**
215
+ * Withdraw funds
216
+ * @param amount - The amount of funds to withdraw
217
+ * @returns The transaction signature or versioned transaction
218
+ */
219
+ withdrawFunds(amount) {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ const ixs = [
222
+ yield this.program.methods
223
+ .withdrawFunds(new anchor_1.BN(amount * Math.pow(10, 6)))
224
+ .accounts({
225
+ signer: this.program.provider.publicKey,
226
+ payer: this.rpcOptions.payer
227
+ })
228
+ .instruction()
229
+ ];
230
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
231
+ });
232
+ }
180
233
  }
181
234
  exports.default = PoseidonsProtocolClient;