@triadxyz/triad-protocol 0.1.0 → 0.1.1-alpha.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.
- package/README.md +27 -0
- package/dist/index.d.ts +36 -3
- package/dist/index.js +30 -11
- package/dist/ticker.d.ts +34 -0
- package/dist/ticker.js +51 -0
- package/dist/types/triad_protocol.d.ts +555 -21
- package/dist/types/triad_protocol.js +555 -21
- package/dist/utils/constants.d.ts +1 -1
- package/dist/utils/constants.js +1 -1
- package/dist/utils/helpers.d.ts +6 -1
- package/dist/utils/helpers.js +57 -4
- package/dist/vault.d.ts +75 -0
- package/dist/vault.js +161 -0
- package/package.json +4 -3
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>Triad Protocol</h1>
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
The official Triad Protocol. trading your prefer companie in web3.
|
|
6
|
+
|
|
7
|
+
### Docs
|
|
8
|
+
|
|
9
|
+
[Triad Protocol Docs](https://docs.triadfi.co/)
|
|
10
|
+
|
|
11
|
+
## Quick Setup
|
|
12
|
+
|
|
13
|
+
### Install
|
|
14
|
+
|
|
15
|
+
Install these dependencies over:
|
|
16
|
+
|
|
17
|
+
npm:
|
|
18
|
+
|
|
19
|
+
```shell
|
|
20
|
+
npm install @triadxyz/triad-protocol
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
yarn:
|
|
24
|
+
|
|
25
|
+
```shell
|
|
26
|
+
yarn add @triadxyz/triad-protocol
|
|
27
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,43 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
|
|
2
|
-
import { Connection } from '@solana/web3.js';
|
|
3
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
3
4
|
import { TriadProtocol } from './types/triad_protocol';
|
|
5
|
+
import Ticker from './ticker';
|
|
6
|
+
import Vault from './vault';
|
|
4
7
|
export default class TriadProtocolClient {
|
|
5
8
|
program: Program<TriadProtocol>;
|
|
6
9
|
provider: AnchorProvider;
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
ticker: Ticker;
|
|
11
|
+
vault: Vault;
|
|
9
12
|
constructor(connection: Connection, wallet: Wallet);
|
|
13
|
+
getUserPositions: (userWallet: PublicKey) => Promise<{
|
|
14
|
+
ticker: import("@coral-xyz/anchor").ProgramAccount<{
|
|
15
|
+
initTs: import("bn.js");
|
|
16
|
+
updatedTs: import("bn.js");
|
|
17
|
+
bump: number;
|
|
18
|
+
authority: PublicKey;
|
|
19
|
+
name: string;
|
|
20
|
+
protocolProgramId: PublicKey;
|
|
21
|
+
price: import("bn.js");
|
|
22
|
+
vault: PublicKey;
|
|
23
|
+
}>;
|
|
24
|
+
position: {
|
|
25
|
+
ts: import("bn.js");
|
|
26
|
+
bump: number;
|
|
27
|
+
totalDeposited: import("bn.js");
|
|
28
|
+
totalWithdrawn: import("bn.js");
|
|
29
|
+
lpShare: import("bn.js");
|
|
30
|
+
totalPositions: number;
|
|
31
|
+
ticker: PublicKey;
|
|
32
|
+
authority: PublicKey;
|
|
33
|
+
positions: {
|
|
34
|
+
amount: import("bn.js");
|
|
35
|
+
entryPrice: import("bn.js");
|
|
36
|
+
ts: import("bn.js");
|
|
37
|
+
isLong: boolean;
|
|
38
|
+
isOpen: boolean;
|
|
39
|
+
pnl: import("bn.js");
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
42
|
+
}[]>;
|
|
10
43
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,41 @@
|
|
|
1
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
|
+
};
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
4
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
5
16
|
const triad_protocol_1 = require("./types/triad_protocol");
|
|
6
17
|
const constants_1 = require("./utils/constants");
|
|
7
|
-
const
|
|
18
|
+
const ticker_1 = __importDefault(require("./ticker"));
|
|
19
|
+
const vault_1 = __importDefault(require("./vault"));
|
|
20
|
+
const helpers_1 = require("./utils/helpers");
|
|
8
21
|
class TriadProtocolClient {
|
|
9
22
|
constructor(connection, wallet) {
|
|
10
|
-
this.
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
this.getUserPositions = (userWallet) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const tickers = yield this.ticker.getTickers();
|
|
25
|
+
const positions = yield Promise.all(tickers.map((ticker) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const UserPositionPDA = (0, helpers_1.getUserPositionAddressSync)(this.program.programId, userWallet, ticker.publicKey);
|
|
27
|
+
const position = yield this.program.account.userPosition.fetch(UserPositionPDA);
|
|
28
|
+
return {
|
|
29
|
+
ticker,
|
|
30
|
+
position
|
|
31
|
+
};
|
|
32
|
+
})));
|
|
33
|
+
return positions;
|
|
34
|
+
});
|
|
35
|
+
this.provider = new anchor_1.AnchorProvider(connection, wallet, anchor_1.AnchorProvider.defaultOptions());
|
|
13
36
|
this.program = new anchor_1.Program(triad_protocol_1.IDL, constants_1.TRIAD_PROTOCOL_PROGRAM_ID, this.provider);
|
|
37
|
+
this.ticker = new ticker_1.default(this.program, this.provider);
|
|
38
|
+
this.vault = new vault_1.default(this.program, this.provider);
|
|
14
39
|
}
|
|
15
40
|
}
|
|
16
41
|
exports.default = TriadProtocolClient;
|
|
17
|
-
const connection = new web3_js_1.Connection('https://renaissancebr-pit.rpcpool.com/24aa1f64-6e92-4c7b-9599-91956a4220e4');
|
|
18
|
-
const keypair = (0, convertSecretKeyToKeypair_1.convertSecretKeyToKeypair)('DG4SC7Hjk6szDCQWv4kpcmwzUC2A5kkA4t4rPhDMVLhGm1mR9yrVkCseyQZknvfaaTis5Q1dHVtNRmMPVZreRfL');
|
|
19
|
-
const wallet = new anchor_1.Wallet(keypair);
|
|
20
|
-
const triad = new TriadProtocolClient(connection, wallet);
|
|
21
|
-
const main = () => { };
|
|
22
|
-
main();
|
package/dist/ticker.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import { AnchorProvider, Program } from '@coral-xyz/anchor';
|
|
3
|
+
import { PublicKey } from '@solana/web3.js';
|
|
4
|
+
import { TriadProtocol } from './types/triad_protocol';
|
|
5
|
+
export default class Ticker {
|
|
6
|
+
program: Program<TriadProtocol>;
|
|
7
|
+
provider: AnchorProvider;
|
|
8
|
+
constructor(program: Program<TriadProtocol>, provider: AnchorProvider);
|
|
9
|
+
/**
|
|
10
|
+
* Get all tickers
|
|
11
|
+
*/
|
|
12
|
+
getTickers(): Promise<import("@coral-xyz/anchor").ProgramAccount<{
|
|
13
|
+
initTs: import("bn.js");
|
|
14
|
+
updatedTs: import("bn.js");
|
|
15
|
+
bump: number;
|
|
16
|
+
authority: PublicKey;
|
|
17
|
+
name: string;
|
|
18
|
+
protocolProgramId: PublicKey;
|
|
19
|
+
price: import("bn.js");
|
|
20
|
+
vault: PublicKey;
|
|
21
|
+
}>[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new ticker
|
|
24
|
+
* @param name - The ticker's name
|
|
25
|
+
* @param protocolProgramId - The program ID of the protocol
|
|
26
|
+
* @param token mint - Token mint for the ticker (e.g. USDC)
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
createTicker({ name, protocolProgramId, tokenMint }: {
|
|
30
|
+
name: string;
|
|
31
|
+
protocolProgramId: PublicKey;
|
|
32
|
+
tokenMint: PublicKey;
|
|
33
|
+
}): Promise<string>;
|
|
34
|
+
}
|
package/dist/ticker.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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 helpers_1 = require("./utils/helpers");
|
|
13
|
+
class Ticker {
|
|
14
|
+
constructor(program, provider) {
|
|
15
|
+
this.provider = provider;
|
|
16
|
+
this.program = program;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get all tickers
|
|
20
|
+
*/
|
|
21
|
+
getTickers() {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
return this.program.account.ticker.all();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create a new ticker
|
|
28
|
+
* @param name - The ticker's name
|
|
29
|
+
* @param protocolProgramId - The program ID of the protocol
|
|
30
|
+
* @param token mint - Token mint for the ticker (e.g. USDC)
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
createTicker({ name, protocolProgramId, tokenMint }) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const TickerPDA = (0, helpers_1.getTickerAddressSync)(this.program.programId, name);
|
|
36
|
+
const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, TickerPDA);
|
|
37
|
+
const TokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
|
|
38
|
+
return this.program.methods
|
|
39
|
+
.createTicker({ name, protocolProgramId })
|
|
40
|
+
.accounts({
|
|
41
|
+
signer: this.provider.wallet.publicKey,
|
|
42
|
+
ticker: TickerPDA,
|
|
43
|
+
vault: VaultPDA,
|
|
44
|
+
tokenAccount: TokenAccountPDA,
|
|
45
|
+
payerTokenMint: tokenMint
|
|
46
|
+
})
|
|
47
|
+
.rpc();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.default = Ticker;
|