@triadxyz/triad-protocol 1.6.2-beta → 1.6.3-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 +2 -0
- package/dist/index.js +2 -0
- package/dist/local-test/index.d.ts +1 -0
- package/dist/local-test/index.js +449 -0
- package/dist/local-test/init-market.d.ts +8 -0
- package/dist/local-test/init-market.js +63 -0
- package/dist/local-test/simulate-market.d.ts +54 -0
- package/dist/local-test/simulate-market.js +156 -0
- package/dist/stake.js +1 -3
- package/dist/trade.d.ts +10 -31
- package/dist/trade.js +17 -59
- package/dist/types/idl_triad_protocol.json +595 -79
- package/dist/types/trade.d.ts +1 -0
- package/dist/types/trade.js +1 -0
- package/dist/types/triad_protocol.d.ts +709 -77
- package/dist/utils/constants.d.ts +2 -2
- package/dist/utils/constants.js +3 -3
- package/dist/utils/getPriorityFee.js +9 -2
- package/dist/utils/helpers.d.ts +0 -2
- package/dist/utils/helpers.js +1 -11
- package/dist/utils/pda/index.d.ts +1 -5
- package/dist/utils/pda/index.js +4 -20
- package/dist/utils/pda/stake.d.ts +0 -1
- package/dist/utils/pda/stake.js +1 -5
- package/dist/wheel.d.ts +65 -0
- package/dist/wheel.js +142 -0
- package/package.json +2 -2
- package/dist/utils/getRarityRank.d.ts +0 -6
- package/dist/utils/getRarityRank.js +0 -7
|
@@ -6,8 +6,8 @@ export declare const TRD_MINT: PublicKey;
|
|
|
6
6
|
export declare const TRIAD_ADMIN: PublicKey;
|
|
7
7
|
export declare const SOL_MINT: PublicKey;
|
|
8
8
|
export declare const TICKET_CORE_COLLECTION: PublicKey;
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
9
|
+
export declare const VALENT_SPIN_NAME = "valent";
|
|
10
|
+
export declare const WHEEL_MINT: PublicKey;
|
|
11
11
|
export declare const POSEIDON_COLLECTION_SYMBOL = "$PSN";
|
|
12
12
|
export declare const POSEIDON_CORE_COLLECTION: PublicKey;
|
|
13
13
|
export declare const TICKET_COLLECTION_SYMBOL = "PTCKT";
|
package/dist/utils/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TICKET_COLLECTION_SYMBOL = exports.POSEIDON_CORE_COLLECTION = exports.POSEIDON_COLLECTION_SYMBOL = exports.
|
|
3
|
+
exports.TICKET_COLLECTION_SYMBOL = exports.POSEIDON_CORE_COLLECTION = exports.POSEIDON_COLLECTION_SYMBOL = exports.WHEEL_MINT = exports.VALENT_SPIN_NAME = exports.TICKET_CORE_COLLECTION = exports.SOL_MINT = exports.TRIAD_ADMIN = exports.TRD_MINT = exports.VERIFIER = exports.TRD_DECIMALS = exports.STAKE_VAULT_NAME = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
exports.STAKE_VAULT_NAME = 'Triad Share 1';
|
|
6
6
|
exports.TRD_DECIMALS = 6;
|
|
@@ -9,8 +9,8 @@ exports.TRD_MINT = new web3_js_1.PublicKey('t3DohmswhKk94PPbPYwA6ZKACyY3y5kbcqeQ
|
|
|
9
9
|
exports.TRIAD_ADMIN = new web3_js_1.PublicKey('82ppCojm3yrEKgdpH8B5AmBJTU1r1uAWXFWhxvPs9UCR');
|
|
10
10
|
exports.SOL_MINT = new web3_js_1.PublicKey('So11111111111111111111111111111111111111112');
|
|
11
11
|
exports.TICKET_CORE_COLLECTION = new web3_js_1.PublicKey('BaqopH1VXYUCT6VsojbTibVcd3k5jpGGT6296HFb6fVa');
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
12
|
+
exports.VALENT_SPIN_NAME = 'valent';
|
|
13
|
+
exports.WHEEL_MINT = new web3_js_1.PublicKey('tCMraBSGHeMcQS76hNnBhnfbMzrtnnT3nbt3vAnSCE2');
|
|
14
14
|
exports.POSEIDON_COLLECTION_SYMBOL = '$PSN';
|
|
15
15
|
exports.POSEIDON_CORE_COLLECTION = new web3_js_1.PublicKey('69CLccefLRmvDSAJP7Er632dvn878qkpdcnvq5ZUspSm');
|
|
16
16
|
exports.TICKET_COLLECTION_SYMBOL = 'PTCKT';
|
|
@@ -14,7 +14,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const axios_1 = __importDefault(require("axios"));
|
|
16
16
|
const getPriorityFee = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
let fee = 1000;
|
|
18
|
+
try {
|
|
19
|
+
const response = yield axios_1.default.get('https://solanacompass.com/api/fees');
|
|
20
|
+
fee = response.data[1].priorityTx;
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
fee = 1000;
|
|
24
|
+
}
|
|
25
|
+
return fee;
|
|
19
26
|
});
|
|
20
27
|
exports.default = getPriorityFee;
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Stake, StakeVault } from './../types/stake';
|
|
2
|
-
import { User } from './../types';
|
|
3
2
|
import { Market, Order, UserTrade } from '../types/trade';
|
|
4
3
|
import { PublicKey } from '@solana/web3.js';
|
|
5
4
|
export declare const encodeString: (value: string, alloc?: number) => number[];
|
|
6
5
|
export declare const decodeString: (bytes: number[]) => string;
|
|
7
6
|
export declare const formatStakeVault: (stakeVault: any) => StakeVault;
|
|
8
7
|
export declare const formatStake: (stake: any) => Stake;
|
|
9
|
-
export declare const formatUser: (user: any) => User;
|
|
10
8
|
export declare const formatMarket: (account: any, address: PublicKey) => Market;
|
|
11
9
|
export declare const formatOrder: (order: any) => Order;
|
|
12
10
|
export declare const formatUserTrade: (account: any, publicKey: PublicKey) => UserTrade;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateStakeRewards = exports.formatUserTrade = exports.formatOrder = exports.formatMarket = exports.
|
|
3
|
+
exports.calculateStakeRewards = exports.formatUserTrade = exports.formatOrder = exports.formatMarket = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
|
|
4
4
|
const trade_1 = require("../types/trade");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
const encodeString = (value, alloc = 32) => {
|
|
@@ -50,16 +50,6 @@ const formatStake = (stake) => {
|
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
52
|
exports.formatStake = formatStake;
|
|
53
|
-
const formatUser = (user) => {
|
|
54
|
-
return {
|
|
55
|
-
ts: user.ts.toNumber(),
|
|
56
|
-
authority: user.authority.toBase58(),
|
|
57
|
-
referral: user.referral,
|
|
58
|
-
referred: user.referred.toNumber(),
|
|
59
|
-
name: user.name
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
exports.formatUser = formatUser;
|
|
63
53
|
const formatMarket = (account, address) => {
|
|
64
54
|
return {
|
|
65
55
|
bump: account.bump,
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
export declare const getUserPDA: (programId: PublicKey, wallet: PublicKey) => PublicKey;
|
|
3
|
-
export declare const getTickerPDA: (programId: PublicKey, tickerName: string) => PublicKey;
|
|
4
|
-
export declare const getVaultAddressSync: (programId: PublicKey, tickerAddress: PublicKey) => PublicKey;
|
|
5
2
|
export declare const getUserPositionPDA: (programId: PublicKey, wallet: PublicKey, ticker: PublicKey) => PublicKey;
|
|
6
|
-
export declare const getTokenVaultAddressSync: (programId: PublicKey, vault: PublicKey) => PublicKey;
|
|
7
3
|
export declare const getTokenATA: (address: PublicKey, Mint: PublicKey) => PublicKey;
|
|
8
|
-
export declare const
|
|
4
|
+
export declare const getWheelPDA: (programId: PublicKey, name: string) => PublicKey;
|
|
9
5
|
export declare const getCollectionPDA: (programId: PublicKey, collectionSymbol: string) => PublicKey;
|
|
10
6
|
export declare const getNftPDA: (programId: PublicKey, number: number) => PublicKey;
|
|
11
7
|
export declare const getPoseidonPDA: (programId: PublicKey, number: number) => PublicKey;
|
package/dist/utils/pda/index.js
CHANGED
|
@@ -3,38 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPoseidonPDA = exports.getNftPDA = exports.getCollectionPDA = exports.
|
|
6
|
+
exports.getPoseidonPDA = exports.getNftPDA = exports.getCollectionPDA = exports.getWheelPDA = exports.getTokenATA = exports.getUserPositionPDA = void 0;
|
|
7
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
8
8
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
9
9
|
const spl_token_1 = require("@solana/spl-token");
|
|
10
|
-
const getUserPDA = (programId, wallet) => {
|
|
11
|
-
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('user'), wallet.toBuffer()], programId)[0];
|
|
12
|
-
};
|
|
13
|
-
exports.getUserPDA = getUserPDA;
|
|
14
|
-
const getTickerPDA = (programId, tickerName) => {
|
|
15
|
-
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('ticker'), Buffer.from(tickerName)], programId)[0];
|
|
16
|
-
};
|
|
17
|
-
exports.getTickerPDA = getTickerPDA;
|
|
18
|
-
const getVaultAddressSync = (programId, tickerAddress) => {
|
|
19
|
-
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('vault'), tickerAddress.toBuffer()], programId)[0];
|
|
20
|
-
};
|
|
21
|
-
exports.getVaultAddressSync = getVaultAddressSync;
|
|
22
10
|
const getUserPositionPDA = (programId, wallet, ticker) => {
|
|
23
11
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('user_position'), wallet.toBuffer(), ticker.toBuffer()], programId)[0];
|
|
24
12
|
};
|
|
25
13
|
exports.getUserPositionPDA = getUserPositionPDA;
|
|
26
|
-
const getTokenVaultAddressSync = (programId, vault) => {
|
|
27
|
-
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('vault_token_account'), vault.toBuffer()], programId)[0];
|
|
28
|
-
};
|
|
29
|
-
exports.getTokenVaultAddressSync = getTokenVaultAddressSync;
|
|
30
14
|
const getTokenATA = (address, Mint) => {
|
|
31
15
|
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];
|
|
32
16
|
};
|
|
33
17
|
exports.getTokenATA = getTokenATA;
|
|
34
|
-
const
|
|
35
|
-
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('
|
|
18
|
+
const getWheelPDA = (programId, name) => {
|
|
19
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('wheel'), Buffer.from(name)], programId)[0];
|
|
36
20
|
};
|
|
37
|
-
exports.
|
|
21
|
+
exports.getWheelPDA = getWheelPDA;
|
|
38
22
|
const getCollectionPDA = (programId, collectionSymbol) => {
|
|
39
23
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('collection'), Buffer.from(collectionSymbol)], programId)[0];
|
|
40
24
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
2
|
export declare const getStakeVaultPDA: (programId: PublicKey, vaultName: string) => PublicKey;
|
|
3
3
|
export declare const getStakePDA: (programId: PublicKey, wallet: PublicKey, name: string) => PublicKey;
|
|
4
|
-
export declare const getNFTRewardsPDA: (programId: PublicKey, stake: PublicKey) => PublicKey;
|
package/dist/utils/pda/stake.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getStakePDA = exports.getStakeVaultPDA = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
const getStakeVaultPDA = (programId, vaultName) => {
|
|
6
6
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('stake_vault'), Buffer.from(vaultName)], programId)[0];
|
|
@@ -10,7 +10,3 @@ const getStakePDA = (programId, wallet, name) => {
|
|
|
10
10
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('stake'), wallet.toBuffer(), Buffer.from(name)], programId)[0];
|
|
11
11
|
};
|
|
12
12
|
exports.getStakePDA = getStakePDA;
|
|
13
|
-
const getNFTRewardsPDA = (programId, stake) => {
|
|
14
|
-
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('nft_rewards'), stake.toBuffer()], programId)[0];
|
|
15
|
-
};
|
|
16
|
-
exports.getNFTRewardsPDA = getNFTRewardsPDA;
|
package/dist/wheel.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import { AnchorProvider, BN, Program } from '@coral-xyz/anchor';
|
|
3
|
+
import { Keypair } from '@solana/web3.js';
|
|
4
|
+
import { TriadProtocol } from './types/triad_protocol';
|
|
5
|
+
import { RpcOptions } from './types';
|
|
6
|
+
export default class Wheel {
|
|
7
|
+
private program;
|
|
8
|
+
private provider;
|
|
9
|
+
constructor(program: Program<TriadProtocol>, provider: AnchorProvider);
|
|
10
|
+
/**
|
|
11
|
+
* Add Whell Prize
|
|
12
|
+
* @param args.rangeMin - Range min to get prize
|
|
13
|
+
* @param args.rangeMax - Range max to get prize
|
|
14
|
+
* @param args.prize - Prize number it's indentifier
|
|
15
|
+
* @param args.availableQuantity - Amount available to get
|
|
16
|
+
* @param args.amount - Amount to send
|
|
17
|
+
*
|
|
18
|
+
* @param options - RPC options
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
addWheelPrize({ rangeMin, rangeMax, prize, availableQuantity, amount }: {
|
|
22
|
+
rangeMin: number;
|
|
23
|
+
rangeMax: number;
|
|
24
|
+
prize: number;
|
|
25
|
+
availableQuantity: number;
|
|
26
|
+
amount: number;
|
|
27
|
+
}, options?: RpcOptions): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Claim Wheel Token
|
|
30
|
+
* @param amount - Amount of tokens to claim
|
|
31
|
+
* @param verifier - Verifier keypair
|
|
32
|
+
*
|
|
33
|
+
* @param options - RPC options
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
claimWheelToken(amount: number, verifier: Keypair, options?: RpcOptions): Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Spin Wheel
|
|
39
|
+
* @param args.isSol - Whether to pay with SOL or token
|
|
40
|
+
* @param args.verifier - Verifier keypair
|
|
41
|
+
* @param args.prize - Prize number
|
|
42
|
+
*
|
|
43
|
+
* @param options - RPC options
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
spinWheel(args: {
|
|
47
|
+
isSol: boolean;
|
|
48
|
+
prize: number;
|
|
49
|
+
verifier: Keypair;
|
|
50
|
+
}, options?: RpcOptions): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Get Spin Wheel
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
getSpinWheel(): Promise<BN | {
|
|
56
|
+
none: {};
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Swap Wheel Token
|
|
60
|
+
* @param amount - Amount of tokens to buy
|
|
61
|
+
* @param options - RPC options
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
64
|
+
swapWheelToken(amount: number, options?: RpcOptions): Promise<string>;
|
|
65
|
+
}
|
package/dist/wheel.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
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 pda_1 = require("./utils/pda");
|
|
17
|
+
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
18
|
+
const constants_1 = require("./utils/constants");
|
|
19
|
+
const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
|
|
20
|
+
class Wheel {
|
|
21
|
+
constructor(program, provider) {
|
|
22
|
+
this.program = program;
|
|
23
|
+
this.provider = provider;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Add Whell Prize
|
|
27
|
+
* @param args.rangeMin - Range min to get prize
|
|
28
|
+
* @param args.rangeMax - Range max to get prize
|
|
29
|
+
* @param args.prize - Prize number it's indentifier
|
|
30
|
+
* @param args.availableQuantity - Amount available to get
|
|
31
|
+
* @param args.amount - Amount to send
|
|
32
|
+
*
|
|
33
|
+
* @param options - RPC options
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
addWheelPrize({ rangeMin, rangeMax, prize, availableQuantity, amount }, options) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const method = this.program.methods
|
|
39
|
+
.addWheelPrize({
|
|
40
|
+
name: constants_1.VALENT_SPIN_NAME,
|
|
41
|
+
rangeMin: new anchor_1.BN(rangeMin),
|
|
42
|
+
rangeMax: new anchor_1.BN(rangeMax),
|
|
43
|
+
prize: new anchor_1.BN(prize),
|
|
44
|
+
availableQuantity: new anchor_1.BN(availableQuantity),
|
|
45
|
+
amount: new anchor_1.BN(amount)
|
|
46
|
+
})
|
|
47
|
+
.accounts({
|
|
48
|
+
signer: this.provider.wallet.publicKey
|
|
49
|
+
});
|
|
50
|
+
return (0, sendTransactionWithOptions_1.default)(method, options);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Claim Wheel Token
|
|
55
|
+
* @param amount - Amount of tokens to claim
|
|
56
|
+
* @param verifier - Verifier keypair
|
|
57
|
+
*
|
|
58
|
+
* @param options - RPC options
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
claimWheelToken(amount, verifier, options) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const ix = yield this.program.methods
|
|
64
|
+
.claimWheelToken({
|
|
65
|
+
name: constants_1.VALENT_SPIN_NAME,
|
|
66
|
+
amount: new anchor_1.BN(amount * Math.pow(10, 6))
|
|
67
|
+
})
|
|
68
|
+
.accounts({
|
|
69
|
+
signer: this.provider.wallet.publicKey,
|
|
70
|
+
verifier: verifier.publicKey,
|
|
71
|
+
mint: constants_1.WHEEL_MINT
|
|
72
|
+
})
|
|
73
|
+
.instruction();
|
|
74
|
+
return (0, sendVersionedTransaction_1.default)(this.provider, [ix], options, undefined, [], verifier);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Spin Wheel
|
|
79
|
+
* @param args.isSol - Whether to pay with SOL or token
|
|
80
|
+
* @param args.verifier - Verifier keypair
|
|
81
|
+
* @param args.prize - Prize number
|
|
82
|
+
*
|
|
83
|
+
* @param options - RPC options
|
|
84
|
+
*
|
|
85
|
+
*/
|
|
86
|
+
spinWheel(args, options) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
const wheelPDA = (0, pda_1.getWheelPDA)(this.program.programId, constants_1.VALENT_SPIN_NAME);
|
|
89
|
+
const ix = yield this.program.methods
|
|
90
|
+
.spinWheel({
|
|
91
|
+
isSol: args.isSol,
|
|
92
|
+
prize: new anchor_1.BN(args.prize)
|
|
93
|
+
})
|
|
94
|
+
.accounts({
|
|
95
|
+
signer: this.provider.wallet.publicKey,
|
|
96
|
+
verifier: constants_1.VERIFIER,
|
|
97
|
+
wheel: wheelPDA,
|
|
98
|
+
mint: constants_1.WHEEL_MINT
|
|
99
|
+
})
|
|
100
|
+
.instruction();
|
|
101
|
+
return (0, sendVersionedTransaction_1.default)(this.provider, [ix], options, undefined, [], args.verifier);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get Spin Wheel
|
|
106
|
+
*
|
|
107
|
+
*/
|
|
108
|
+
getSpinWheel() {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
const [wheel] = yield this.program.account.wheel.all();
|
|
111
|
+
const randomNumber = Math.floor(Math.random() * 1000000) + 1;
|
|
112
|
+
const prize = wheel.account.prizes.find((p) => randomNumber >= p.rangeMin.toNumber() &&
|
|
113
|
+
randomNumber <= p.rangeMax.toNumber() &&
|
|
114
|
+
p.status.claimed);
|
|
115
|
+
if (!prize) {
|
|
116
|
+
return { none: {} };
|
|
117
|
+
}
|
|
118
|
+
return prize.prize;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Swap Wheel Token
|
|
123
|
+
* @param amount - Amount of tokens to buy
|
|
124
|
+
* @param options - RPC options
|
|
125
|
+
*
|
|
126
|
+
*/
|
|
127
|
+
swapWheelToken(amount, options) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const method = this.program.methods
|
|
130
|
+
.swapWheelToken({
|
|
131
|
+
name: constants_1.VALENT_SPIN_NAME,
|
|
132
|
+
amount: new anchor_1.BN(amount)
|
|
133
|
+
})
|
|
134
|
+
.accounts({
|
|
135
|
+
signer: this.provider.wallet.publicKey,
|
|
136
|
+
mint: constants_1.WHEEL_MINT
|
|
137
|
+
});
|
|
138
|
+
return (0, sendTransactionWithOptions_1.default)(method, options);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.default = Wheel;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@triadxyz/triad-protocol",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3-beta",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"clean": "rimraf dist",
|
|
9
9
|
"build": "yarn run clean && tsc",
|
|
10
10
|
"prepublishOnly": "yarn build",
|
|
11
|
-
"test": "rimraf dist && tsc && node ./dist/local-test.js"
|
|
11
|
+
"test": "rimraf dist && tsc && node ./dist/local-test/index.js"
|
|
12
12
|
},
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const getRarityRank = (ranks, onchainId, name) => {
|
|
4
|
-
const item = ranks.find((entry) => entry.onchainId === onchainId || entry.name === name);
|
|
5
|
-
return item ? item.rarityRankHrtt : 963;
|
|
6
|
-
};
|
|
7
|
-
exports.default = getRarityRank;
|