@triadxyz/poseidons-protocol 0.1.0 → 0.1.2

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,7 +58,7 @@ 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
61
+ * @param power - The power to add
52
62
  * @returns The transaction signature or versioned transaction
53
63
  */
54
64
  addPoseidonRewards(poseidons: {
@@ -63,4 +73,16 @@ export default class PoseidonsProtocolClient {
63
73
  * @returns The transaction signature or versioned transaction
64
74
  */
65
75
  burnNft(mint: PublicKey, burnMint: PublicKey): Promise<string | import("@solana/web3.js").VersionedTransaction>;
76
+ /**
77
+ * Create a user
78
+ * @param refer - The refer of the user
79
+ * @returns The transaction signature or versioned transaction
80
+ */
81
+ createUser(refer: PublicKey): Promise<string | import("@solana/web3.js").VersionedTransaction>;
82
+ /**
83
+ * Withdraw funds
84
+ * @param amount - The amount of funds to withdraw
85
+ * @returns The transaction signature or versioned transaction
86
+ */
87
+ withdrawFunds(amount: number): Promise<string | import("@solana/web3.js").VersionedTransaction>;
66
88
  }
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,7 @@ 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
157
+ * @param power - The power to add
142
158
  * @returns The transaction signature or versioned transaction
143
159
  */
144
160
  addPoseidonRewards(poseidons) {
@@ -177,5 +193,43 @@ class PoseidonsProtocolClient {
177
193
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
178
194
  });
179
195
  }
196
+ /**
197
+ * Create a user
198
+ * @param refer - The refer of the user
199
+ * @returns The transaction signature or versioned transaction
200
+ */
201
+ createUser(refer) {
202
+ return __awaiter(this, void 0, void 0, function* () {
203
+ const ixs = [
204
+ yield this.program.methods
205
+ .createUser(refer)
206
+ .accounts({
207
+ signer: this.program.provider.publicKey,
208
+ payer: this.rpcOptions.payer
209
+ })
210
+ .instruction()
211
+ ];
212
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
213
+ });
214
+ }
215
+ /**
216
+ * Withdraw funds
217
+ * @param amount - The amount of funds to withdraw
218
+ * @returns The transaction signature or versioned transaction
219
+ */
220
+ withdrawFunds(amount) {
221
+ return __awaiter(this, void 0, void 0, function* () {
222
+ const ixs = [
223
+ yield this.program.methods
224
+ .withdrawFunds(new anchor_1.BN(amount * Math.pow(10, 6)))
225
+ .accounts({
226
+ signer: this.program.provider.publicKey,
227
+ payer: this.rpcOptions.payer
228
+ })
229
+ .instruction()
230
+ ];
231
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
232
+ });
233
+ }
180
234
  }
181
235
  exports.default = PoseidonsProtocolClient;