@triadxyz/triad-protocol 1.1.1-beta → 1.1.2-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 +40 -0
- package/dist/index.js +41 -0
- package/dist/local-test.js +6 -2
- package/dist/utils/pda/index.d.ts +3 -0
- package/dist/utils/pda/index.js +13 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
|
|
2
3
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
3
4
|
import { TriadProtocol } from './types/triad_protocol';
|
|
@@ -22,6 +23,16 @@ export default class TriadProtocolClient {
|
|
|
22
23
|
*
|
|
23
24
|
*/
|
|
24
25
|
getUsers(): Promise<import("./types").User[]>;
|
|
26
|
+
getTickers(): Promise<import("@coral-xyz/anchor").ProgramAccount<{
|
|
27
|
+
initTs: import("bn.js");
|
|
28
|
+
updatedTs: import("bn.js");
|
|
29
|
+
bump: number;
|
|
30
|
+
authority: PublicKey;
|
|
31
|
+
name: string;
|
|
32
|
+
protocolProgramId: PublicKey;
|
|
33
|
+
price: import("bn.js");
|
|
34
|
+
vault: PublicKey;
|
|
35
|
+
}>[]>;
|
|
25
36
|
/**
|
|
26
37
|
* Check if user exists
|
|
27
38
|
* @param username - User name
|
|
@@ -44,4 +55,33 @@ export default class TriadProtocolClient {
|
|
|
44
55
|
*
|
|
45
56
|
*/
|
|
46
57
|
createUser({ wallet, name, referral }: CreateUserArgs, options?: RpcOptions): Promise<any>;
|
|
58
|
+
/**
|
|
59
|
+
* Get User Positions with amount
|
|
60
|
+
* @param wallet - User wallet
|
|
61
|
+
*
|
|
62
|
+
*/
|
|
63
|
+
getUserPositionsWithAmount(wallet: PublicKey): Promise<{
|
|
64
|
+
ts: import("bn.js");
|
|
65
|
+
bump: number;
|
|
66
|
+
totalDeposited: import("bn.js");
|
|
67
|
+
totalWithdrawn: import("bn.js");
|
|
68
|
+
lpShare: import("bn.js");
|
|
69
|
+
totalPositions: number;
|
|
70
|
+
ticker: PublicKey;
|
|
71
|
+
authority: PublicKey;
|
|
72
|
+
positions: {
|
|
73
|
+
amount: import("bn.js");
|
|
74
|
+
entryPrice: import("bn.js");
|
|
75
|
+
ts: import("bn.js");
|
|
76
|
+
isLong: boolean;
|
|
77
|
+
isOpen: boolean;
|
|
78
|
+
pnl: import("bn.js");
|
|
79
|
+
}[];
|
|
80
|
+
}[]>;
|
|
81
|
+
withdrawV1({ wallet, ticker, userPosition, positionIndex }: {
|
|
82
|
+
wallet: PublicKey;
|
|
83
|
+
userPosition: PublicKey;
|
|
84
|
+
ticker: PublicKey;
|
|
85
|
+
positionIndex: number;
|
|
86
|
+
}, options?: RpcOptions): Promise<any>;
|
|
47
87
|
}
|
package/dist/index.js
CHANGED
|
@@ -13,9 +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 web3_js_1 = require("@solana/web3.js");
|
|
16
17
|
const idl_triad_protocol_json_1 = __importDefault(require("./types/idl_triad_protocol.json"));
|
|
17
18
|
const trade_1 = __importDefault(require("./trade"));
|
|
18
19
|
const helpers_1 = require("./utils/helpers");
|
|
20
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
19
21
|
const pda_1 = require("./utils/pda");
|
|
20
22
|
const stake_1 = __importDefault(require("./stake"));
|
|
21
23
|
const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
|
|
@@ -53,6 +55,11 @@ class TriadProtocolClient {
|
|
|
53
55
|
.sort((a, b) => b.referred - a.referred);
|
|
54
56
|
});
|
|
55
57
|
}
|
|
58
|
+
getTickers() {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
return yield this.program.account.ticker.all();
|
|
61
|
+
});
|
|
62
|
+
}
|
|
56
63
|
/**
|
|
57
64
|
* Check if user exists
|
|
58
65
|
* @param username - User name
|
|
@@ -117,5 +124,39 @@ class TriadProtocolClient {
|
|
|
117
124
|
}), options);
|
|
118
125
|
});
|
|
119
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Get User Positions with amount
|
|
129
|
+
* @param wallet - User wallet
|
|
130
|
+
*
|
|
131
|
+
*/
|
|
132
|
+
getUserPositionsWithAmount(wallet) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
const tickers = yield this.program.account.ticker.all();
|
|
135
|
+
const userPositions = [];
|
|
136
|
+
for (const ticker of tickers) {
|
|
137
|
+
const userPositionPDA = (0, pda_1.getUserPositionPDA)(this.program.programId, wallet, ticker.publicKey);
|
|
138
|
+
userPositions.push(userPositionPDA);
|
|
139
|
+
}
|
|
140
|
+
const userPositionsWithAmount = yield this.program.account.userPosition.fetchMultiple(userPositions);
|
|
141
|
+
return userPositionsWithAmount.filter((item) => item &&
|
|
142
|
+
parseFloat(item.totalDeposited.toString()) >
|
|
143
|
+
parseFloat(item.totalWithdrawn.toString()));
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
withdrawV1({ wallet, ticker, userPosition, positionIndex }, options) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
const vaultPDA = (0, pda_1.getVaultAddressSync)(this.program.programId, ticker);
|
|
149
|
+
const VaultTokenAccountPDA = (0, pda_1.getTokenVaultAddressSync)(this.program.programId, vaultPDA);
|
|
150
|
+
const userTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'), this.provider.wallet.publicKey);
|
|
151
|
+
return (0, sendTransactionWithOptions_1.default)(this.program.methods.withdrawV1(positionIndex).accounts({
|
|
152
|
+
signer: wallet,
|
|
153
|
+
userPosition,
|
|
154
|
+
userTokenAccount,
|
|
155
|
+
vault: vaultPDA,
|
|
156
|
+
ticker,
|
|
157
|
+
vaultTokenAccount: VaultTokenAccountPDA
|
|
158
|
+
}), options);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
120
161
|
}
|
|
121
162
|
exports.default = TriadProtocolClient;
|
package/dist/local-test.js
CHANGED
|
@@ -17,7 +17,7 @@ const _1 = __importDefault(require("./"));
|
|
|
17
17
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
18
18
|
const axios_1 = __importDefault(require("axios"));
|
|
19
19
|
const web3_js_1 = require("@solana/web3.js");
|
|
20
|
-
const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/
|
|
20
|
+
const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/triad.json');
|
|
21
21
|
const rpc_file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/rpc.txt');
|
|
22
22
|
const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
|
|
23
23
|
const connection = new web3_js_1.Connection(rpc_file.toString(), 'confirmed');
|
|
@@ -164,4 +164,8 @@ const getReferral = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
164
164
|
const response = yield triadProtocol.getReferral('dannpl');
|
|
165
165
|
console.log(response);
|
|
166
166
|
});
|
|
167
|
-
|
|
167
|
+
const getUserPositions = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
168
|
+
const response = yield triadProtocol.getUserPositionsWithAmount(wallet.publicKey);
|
|
169
|
+
console.log(response);
|
|
170
|
+
});
|
|
171
|
+
getUserPositions();
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
2
|
export declare const getUserPDA: (programId: PublicKey, wallet: PublicKey) => PublicKey;
|
|
3
3
|
export declare const getTickerPDA: (programId: PublicKey, tickerName: string) => PublicKey;
|
|
4
|
+
export declare const getVaultAddressSync: (programId: PublicKey, tickerAddress: PublicKey) => PublicKey;
|
|
5
|
+
export declare const getUserPositionPDA: (programId: PublicKey, wallet: PublicKey, ticker: PublicKey) => PublicKey;
|
|
6
|
+
export declare const getTokenVaultAddressSync: (programId: PublicKey, vault: PublicKey) => PublicKey;
|
|
4
7
|
export declare const getTokenATA: (address: PublicKey, Mint: PublicKey) => PublicKey;
|
package/dist/utils/pda/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTokenATA = exports.getTickerPDA = exports.getUserPDA = void 0;
|
|
3
|
+
exports.getTokenATA = exports.getTokenVaultAddressSync = exports.getUserPositionPDA = exports.getVaultAddressSync = exports.getTickerPDA = exports.getUserPDA = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
const spl_token_1 = require("@solana/spl-token");
|
|
6
6
|
const getUserPDA = (programId, wallet) => {
|
|
@@ -11,6 +11,18 @@ const getTickerPDA = (programId, tickerName) => {
|
|
|
11
11
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('ticker'), Buffer.from(tickerName)], programId)[0];
|
|
12
12
|
};
|
|
13
13
|
exports.getTickerPDA = getTickerPDA;
|
|
14
|
+
const getVaultAddressSync = (programId, tickerAddress) => {
|
|
15
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('vault'), tickerAddress.toBuffer()], programId)[0];
|
|
16
|
+
};
|
|
17
|
+
exports.getVaultAddressSync = getVaultAddressSync;
|
|
18
|
+
const getUserPositionPDA = (programId, wallet, ticker) => {
|
|
19
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('user_position'), wallet.toBuffer(), ticker.toBuffer()], programId)[0];
|
|
20
|
+
};
|
|
21
|
+
exports.getUserPositionPDA = getUserPositionPDA;
|
|
22
|
+
const getTokenVaultAddressSync = (programId, vault) => {
|
|
23
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('vault_token_account'), vault.toBuffer()], programId)[0];
|
|
24
|
+
};
|
|
25
|
+
exports.getTokenVaultAddressSync = getTokenVaultAddressSync;
|
|
14
26
|
const getTokenATA = (address, Mint) => {
|
|
15
27
|
return web3_js_1.PublicKey.findProgramAddressSync([address.toBytes(), spl_token_1.TOKEN_2022_PROGRAM_ID.toBytes(), Mint.toBytes()], new web3_js_1.PublicKey(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID))[0];
|
|
16
28
|
};
|