@triadxyz/triad-protocol 0.4.3-beta → 0.4.4-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
@@ -4,15 +4,13 @@ import { TriadProtocol } from './types/triad_protocol';
4
4
  import Ticker from './ticker';
5
5
  import Vault from './vault';
6
6
  import Stake from './stake';
7
- import { CreateUserArgs, RpcOptions } from './types';
8
- import Ore from './ore';
7
+ import { CreateUserArgs, OpenOreArgs, RpcOptions } from './types';
9
8
  export default class TriadProtocolClient {
10
9
  program: Program<TriadProtocol>;
11
10
  provider: AnchorProvider;
12
11
  ticker: Ticker;
13
12
  vault: Vault;
14
13
  stake: Stake;
15
- ore: Ore;
16
14
  constructor(connection: Connection, wallet: Wallet);
17
15
  /**
18
16
  * Get User by wallet
@@ -43,4 +41,5 @@ export default class TriadProtocolClient {
43
41
  *
44
42
  */
45
43
  createUser: ({ wallet, name, referral }: CreateUserArgs, options?: RpcOptions) => Promise<string>;
44
+ openOre: ({ user, payer, name, referralName }: OpenOreArgs, options?: RpcOptions) => Promise<string>;
46
45
  }
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ const ticker_1 = __importDefault(require("./ticker"));
19
19
  const vault_1 = __importDefault(require("./vault"));
20
20
  const helpers_1 = require("./utils/helpers");
21
21
  const stake_1 = __importDefault(require("./stake"));
22
- const ore_1 = __importDefault(require("./ore"));
22
+ const constants_1 = require("./utils/constants");
23
23
  class TriadProtocolClient {
24
24
  constructor(connection, wallet) {
25
25
  /**
@@ -114,12 +114,55 @@ class TriadProtocolClient {
114
114
  }
115
115
  return method.rpc({ skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight });
116
116
  };
117
+ this.openOre = ({ user, payer, name, referralName }, options) => __awaiter(this, void 0, void 0, function* () {
118
+ const userPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, user);
119
+ const ixs = [];
120
+ try {
121
+ yield this.program.account.user.fetch(userPDA);
122
+ }
123
+ catch (_d) {
124
+ const referral = yield this.getRefferal(referralName);
125
+ ixs.push(yield this.program.methods
126
+ .createUser({
127
+ name
128
+ })
129
+ .accounts({
130
+ signer: user,
131
+ referral
132
+ })
133
+ .instruction());
134
+ }
135
+ const proofInfoPDA = (0, helpers_1.getProofOreAddressSync)(userPDA);
136
+ ixs.push(yield this.program.methods
137
+ .openOre()
138
+ .accounts({
139
+ signer: user,
140
+ minerInfo: userPDA,
141
+ proofInfo: proofInfoPDA,
142
+ sysvarHashesInfo: new web3_js_1.PublicKey('SysvarS1otHashes111111111111111111111111111'),
143
+ oreProgram: new web3_js_1.PublicKey(constants_1.ORE_PROGRAM_ID)
144
+ })
145
+ .instruction());
146
+ if (options === null || options === void 0 ? void 0 : options.microLamports) {
147
+ ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
148
+ microLamports: options.microLamports
149
+ }));
150
+ }
151
+ const { blockhash } = yield this.provider.connection.getLatestBlockhash();
152
+ return this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(new web3_js_1.TransactionMessage({
153
+ instructions: ixs,
154
+ recentBlockhash: blockhash,
155
+ payerKey: payer
156
+ }).compileToV0Message()), [], {
157
+ skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight,
158
+ commitment: 'confirmed'
159
+ });
160
+ });
117
161
  this.provider = new anchor_1.AnchorProvider(connection, wallet, anchor_1.AnchorProvider.defaultOptions());
118
162
  this.program = new anchor_1.Program(idl_triad_protocol_json_1.default, this.provider);
119
163
  this.ticker = new ticker_1.default(this.program, this.provider);
120
164
  this.vault = new vault_1.default(this.program, this.provider);
121
165
  this.stake = new stake_1.default(this.program, this.provider);
122
- this.ore = new ore_1.default(this.program, this.provider);
123
166
  }
124
167
  }
125
168
  exports.default = TriadProtocolClient;
package/dist/test.js CHANGED
@@ -86,11 +86,3 @@ const updateBoost = () => __awaiter(void 0, void 0, void 0, function* () {
86
86
  });
87
87
  console.log(updateBoostResponse);
88
88
  });
89
- const openOre = () => __awaiter(void 0, void 0, void 0, function* () {
90
- const response = yield triadProtocol.ore.openOre(wallet.publicKey, {
91
- microLamports: 2000,
92
- skipPreflight: true
93
- });
94
- console.log(response);
95
- });
96
- openOre();
@@ -8,3 +8,9 @@ export type CreateUserArgs = {
8
8
  name: string;
9
9
  referral?: PublicKey;
10
10
  };
11
+ export type OpenOreArgs = {
12
+ user: PublicKey;
13
+ payer: PublicKey;
14
+ name: string;
15
+ referralName: string;
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "0.4.3-beta",
3
+ "version": "0.4.4-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/dist/ore.d.ts DELETED
@@ -1,10 +0,0 @@
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
- export default class Ore {
6
- program: Program<TriadProtocol>;
7
- provider: AnchorProvider;
8
- constructor(program: Program<TriadProtocol>, provider: AnchorProvider);
9
- openOre: (user: PublicKey, options?: RpcOptions) => Promise<string>;
10
- }
package/dist/ore.js DELETED
@@ -1,40 +0,0 @@
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 web3_js_1 = require("@solana/web3.js");
13
- const helpers_1 = require("./utils/helpers");
14
- const constants_1 = require("./utils/constants");
15
- class Ore {
16
- constructor(program, provider) {
17
- this.openOre = (user, options) => __awaiter(this, void 0, void 0, function* () {
18
- const userPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, user);
19
- const proofInfoPDA = (0, helpers_1.getProofOreAddressSync)(userPDA);
20
- const method = this.program.methods.openOre().accounts({
21
- signer: user,
22
- minerInfo: userPDA,
23
- proofInfo: proofInfoPDA,
24
- sysvarHashesInfo: new web3_js_1.PublicKey('SysvarS1otHashes111111111111111111111111111'),
25
- oreProgram: new web3_js_1.PublicKey(constants_1.ORE_PROGRAM_ID)
26
- });
27
- if (options === null || options === void 0 ? void 0 : options.microLamports) {
28
- method.postInstructions([
29
- web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
30
- microLamports: options.microLamports
31
- })
32
- ]);
33
- }
34
- return method.rpc({ skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight });
35
- });
36
- this.provider = provider;
37
- this.program = program;
38
- }
39
- }
40
- exports.default = Ore;