@triadxyz/triad-protocol 0.1.0-alpha.4 → 0.1.0-alpha.6

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,7 +1,6 @@
1
1
  /// <reference types="bn.js" />
2
- /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
3
2
  import { Address, AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
4
- import { Connection } from '@solana/web3.js';
3
+ import { Connection, PublicKey } from '@solana/web3.js';
5
4
  import { TriadProtocol } from './types/triad_protocol';
6
5
  import Ticker from './ticker';
7
6
  import Vault from './vault';
@@ -18,7 +17,7 @@ export default class TriadProtocolClient {
18
17
  ts: import("bn.js");
19
18
  name: string;
20
19
  bump: number;
21
- authority: import("@solana/web3.js").PublicKey;
20
+ authority: PublicKey;
22
21
  referrer: string;
23
22
  community: string;
24
23
  netDeposits: import("bn.js");
@@ -48,7 +47,7 @@ export default class TriadProtocolClient {
48
47
  ts: import("bn.js");
49
48
  name: string;
50
49
  bump: number;
51
- authority: import("@solana/web3.js").PublicKey;
50
+ authority: PublicKey;
52
51
  referrer: string;
53
52
  community: string;
54
53
  netDeposits: import("bn.js");
package/dist/ticker.js CHANGED
@@ -32,7 +32,7 @@ class Ticker {
32
32
  */
33
33
  createTicker({ name, protocolProgramId, tokenMint }) {
34
34
  return __awaiter(this, void 0, void 0, function* () {
35
- const TickerPDA = (0, helpers_1.getTickerAddressSync)(this.program.programId, protocolProgramId);
35
+ const TickerPDA = (0, helpers_1.getTickerAddressSync)(this.program.programId, name);
36
36
  const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, TickerPDA);
37
37
  const TokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
38
38
  return this.program.methods
@@ -1,6 +1,6 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
2
  import BN from 'bn.js';
3
- export declare const getTickerAddressSync: (programId: PublicKey, protocolProgramId: PublicKey) => PublicKey;
3
+ export declare const getTickerAddressSync: (programId: PublicKey, tickerName: string) => PublicKey;
4
4
  export declare const encodeString: (value: string) => number[];
5
5
  export declare const decodeString: (bytes: number[]) => string;
6
6
  export declare const getVaultAddressSync: (programId: PublicKey, tickerAddress: PublicKey) => PublicKey;
@@ -26,8 +26,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.formatNumber = exports.getUserAddressSync = exports.getTokenVaultAddressSync = exports.getVaultAddressSync = exports.decodeString = exports.encodeString = exports.getTickerAddressSync = void 0;
27
27
  const web3_js_1 = require("@solana/web3.js");
28
28
  const anchor = __importStar(require("@coral-xyz/anchor"));
29
- const getTickerAddressSync = (programId, protocolProgramId) => {
30
- const [TickerPDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('ticker'), protocolProgramId.toBuffer()], programId);
29
+ const getTickerAddressSync = (programId, tickerName) => {
30
+ const [TickerPDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('ticker'), Buffer.from(tickerName)], programId);
31
31
  return TickerPDA;
32
32
  };
33
33
  exports.getTickerAddressSync = getTickerAddressSync;
package/dist/vault.js CHANGED
@@ -51,49 +51,55 @@ class Vault {
51
51
  */
52
52
  openPosition({ tickerPDA, amount, position, mint }) {
53
53
  return __awaiter(this, void 0, void 0, function* () {
54
- const UserPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, this.provider.wallet.publicKey);
55
- const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, tickerPDA);
56
- const VaultTokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
57
- const userTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(mint, this.provider.wallet.publicKey);
58
- let hasUser = false;
59
54
  try {
60
- this.program.account.user.fetch(this.provider.wallet.publicKey);
61
- hasUser = true;
62
- }
63
- catch (_a) { }
64
- const instructions = [];
65
- if (!hasUser) {
55
+ const UserPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, this.provider.wallet.publicKey);
56
+ const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, tickerPDA);
57
+ const VaultTokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
58
+ const userTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(mint, this.provider.wallet.publicKey);
59
+ let hasUser = false;
60
+ try {
61
+ yield this.program.account.user.fetch(this.provider.wallet.publicKey);
62
+ hasUser = true;
63
+ }
64
+ catch (_a) { }
65
+ const instructions = [];
66
+ if (!hasUser) {
67
+ instructions.push(yield this.program.methods
68
+ .createUser({
69
+ name: `User ${Math.floor(Math.random() * 100)}`,
70
+ referrer: '',
71
+ community: ''
72
+ })
73
+ .accounts({
74
+ signer: this.provider.wallet.publicKey,
75
+ user: UserPDA
76
+ })
77
+ .instruction());
78
+ }
66
79
  instructions.push(yield this.program.methods
67
- .createUser({
68
- name: `User ${Math.floor(Math.random() * 100)}`,
69
- referrer: '',
70
- community: ''
80
+ .openPosition({
81
+ amount: new anchor_1.BN(amount),
82
+ isLong: position === 'Long'
71
83
  })
72
84
  .accounts({
73
- signer: this.provider.wallet.publicKey,
74
- user: UserPDA
85
+ user: UserPDA,
86
+ ticker: tickerPDA,
87
+ vault: VaultPDA,
88
+ vaultTokenAccount: VaultTokenAccountPDA,
89
+ userTokenAccount
75
90
  })
76
91
  .instruction());
92
+ const { blockhash } = yield this.provider.connection.getLatestBlockhash();
93
+ const message = new web3_js_1.TransactionMessage({
94
+ payerKey: this.provider.wallet.publicKey,
95
+ recentBlockhash: blockhash,
96
+ instructions
97
+ }).compileToV0Message();
98
+ return this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(message));
99
+ }
100
+ catch (error) {
101
+ console.error(error);
77
102
  }
78
- instructions.push(yield this.program.methods
79
- .openPosition({
80
- amount: new anchor_1.BN(amount),
81
- isLong: position === 'Long'
82
- })
83
- .accounts({
84
- user: UserPDA,
85
- vault: VaultPDA,
86
- vaultTokenAccount: VaultTokenAccountPDA,
87
- userTokenAccount
88
- })
89
- .instruction());
90
- const { blockhash } = yield this.provider.connection.getLatestBlockhash();
91
- const message = new web3_js_1.TransactionMessage({
92
- payerKey: this.provider.wallet.publicKey,
93
- recentBlockhash: blockhash,
94
- instructions
95
- }).compileToV0Message();
96
- return this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(message));
97
103
  });
98
104
  }
99
105
  /**
@@ -107,50 +113,55 @@ class Vault {
107
113
  */
108
114
  closePosition({ tickerPDA, amount, position, mint, positionPubkey }) {
109
115
  return __awaiter(this, void 0, void 0, function* () {
110
- const UserPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, this.provider.wallet.publicKey);
111
- const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, tickerPDA);
112
- const VaultTokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
113
- const userTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(mint, this.provider.wallet.publicKey);
114
- let hasUser = false;
115
116
  try {
116
- this.program.account.user.fetch(this.provider.wallet.publicKey);
117
- hasUser = true;
118
- }
119
- catch (_a) { }
120
- const instructions = [];
121
- if (!hasUser) {
117
+ const UserPDA = (0, helpers_1.getUserAddressSync)(this.program.programId, this.provider.wallet.publicKey);
118
+ const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, tickerPDA);
119
+ const VaultTokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
120
+ const userTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(mint, this.provider.wallet.publicKey);
121
+ let hasUser = false;
122
+ try {
123
+ yield this.program.account.user.fetch(this.provider.wallet.publicKey);
124
+ hasUser = true;
125
+ }
126
+ catch (_a) { }
127
+ const instructions = [];
128
+ if (!hasUser) {
129
+ instructions.push(yield this.program.methods
130
+ .createUser({
131
+ name: `User ${Math.floor(Math.random() * 100)}`,
132
+ referrer: '',
133
+ community: ''
134
+ })
135
+ .accounts({
136
+ signer: this.provider.wallet.publicKey,
137
+ user: UserPDA
138
+ })
139
+ .instruction());
140
+ }
122
141
  instructions.push(yield this.program.methods
123
- .createUser({
124
- name: `User ${Math.floor(Math.random() * 100)}`,
125
- referrer: '',
126
- community: ''
142
+ .closePosition({
143
+ amount: new anchor_1.BN(amount),
144
+ isLong: position === 'Long',
145
+ pubkey: positionPubkey
127
146
  })
128
147
  .accounts({
129
- signer: this.provider.wallet.publicKey,
130
- user: UserPDA
148
+ user: UserPDA,
149
+ vault: VaultPDA,
150
+ vaultTokenAccount: VaultTokenAccountPDA,
151
+ userTokenAccount
131
152
  })
132
153
  .instruction());
154
+ const { blockhash } = yield this.provider.connection.getLatestBlockhash();
155
+ const message = new web3_js_1.TransactionMessage({
156
+ payerKey: this.provider.wallet.publicKey,
157
+ recentBlockhash: blockhash,
158
+ instructions
159
+ }).compileToV0Message();
160
+ return this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(message));
161
+ }
162
+ catch (error) {
163
+ console.error(error);
133
164
  }
134
- instructions.push(yield this.program.methods
135
- .closePosition({
136
- amount: new anchor_1.BN(amount),
137
- isLong: position === 'Long',
138
- pubkey: positionPubkey
139
- })
140
- .accounts({
141
- user: UserPDA,
142
- vault: VaultPDA,
143
- vaultTokenAccount: VaultTokenAccountPDA,
144
- userTokenAccount
145
- })
146
- .instruction());
147
- const { blockhash } = yield this.provider.connection.getLatestBlockhash();
148
- const message = new web3_js_1.TransactionMessage({
149
- payerKey: this.provider.wallet.publicKey,
150
- recentBlockhash: blockhash,
151
- instructions
152
- }).compileToV0Message();
153
- return this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(message));
154
165
  });
155
166
  }
156
167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.6",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "triad",
27
27
  "trading protocols"
28
28
  ],
29
- "author": "Lineup",
29
+ "author": "Triad Labs",
30
30
  "license": "ISC",
31
31
  "dependencies": {
32
32
  "@coral-xyz/anchor": "0.28.0",