@drift-labs/sdk 0.2.0-master.4 → 0.2.0-master.40
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 -27
- package/lib/accounts/bulkAccountLoader.d.ts +2 -0
- package/lib/accounts/bulkAccountLoader.js +36 -29
- package/lib/accounts/bulkUserStatsSubscription.d.ts +7 -0
- package/lib/accounts/bulkUserStatsSubscription.js +21 -0
- package/lib/accounts/bulkUserSubscription.d.ts +2 -2
- package/lib/accounts/bulkUserSubscription.js +0 -1
- package/lib/accounts/fetch.d.ts +2 -1
- package/lib/accounts/fetch.js +9 -1
- package/lib/accounts/{pollingClearingHouseAccountSubscriber.d.ts → pollingDriftClientAccountSubscriber.d.ts} +20 -25
- package/lib/accounts/{pollingClearingHouseAccountSubscriber.js → pollingDriftClientAccountSubscriber.js} +45 -49
- package/lib/accounts/{pollingOracleSubscriber.d.ts → pollingOracleAccountSubscriber.d.ts} +2 -2
- package/lib/accounts/{pollingOracleSubscriber.js → pollingOracleAccountSubscriber.js} +3 -3
- package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +113 -0
- package/lib/accounts/types.d.ts +26 -15
- package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +49 -0
- package/lib/accounts/{webSocketClearingHouseAccountSubscriber.js → webSocketDriftClientAccountSubscriber.js} +47 -45
- package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +20 -0
- package/lib/accounts/webSocketUserStatsAccountSubsriber.js +47 -0
- package/lib/addresses/marketAddresses.d.ts +1 -3
- package/lib/addresses/marketAddresses.js +1 -1
- package/lib/addresses/pda.d.ts +15 -9
- package/lib/addresses/pda.js +73 -35
- package/lib/adminClient.d.ts +65 -0
- package/lib/adminClient.js +637 -0
- package/lib/config.d.ts +9 -9
- package/lib/config.js +25 -21
- package/lib/constants/numericConstants.d.ts +30 -12
- package/lib/constants/numericConstants.js +41 -21
- package/lib/constants/perpMarkets.d.ts +18 -0
- package/lib/constants/{markets.js → perpMarkets.js} +7 -7
- package/lib/constants/spotMarkets.d.ts +19 -0
- package/lib/constants/spotMarkets.js +53 -0
- package/lib/dlob/DLOB.d.ts +82 -0
- package/lib/dlob/DLOB.js +696 -0
- package/lib/dlob/DLOBNode.d.ts +54 -0
- package/lib/dlob/DLOBNode.js +77 -0
- package/lib/dlob/NodeList.d.ts +27 -0
- package/lib/dlob/NodeList.js +144 -0
- package/lib/driftClient.d.ts +233 -0
- package/lib/driftClient.js +2096 -0
- package/lib/{clearingHouseConfig.d.ts → driftClientConfig.d.ts} +9 -9
- package/lib/{clearingHouseConfig.js → driftClientConfig.js} +0 -0
- package/lib/events/eventList.js +3 -0
- package/lib/events/eventSubscriber.d.ts +5 -2
- package/lib/events/eventSubscriber.js +25 -11
- package/lib/events/fetchLogs.d.ts +13 -2
- package/lib/events/fetchLogs.js +40 -12
- package/lib/events/pollingLogProvider.d.ts +2 -1
- package/lib/events/pollingLogProvider.js +7 -3
- package/lib/events/sort.js +8 -11
- package/lib/events/types.d.ts +9 -3
- package/lib/events/types.js +6 -0
- package/lib/events/webSocketLogProvider.js +1 -1
- package/lib/examples/makeTradeExample.js +30 -18
- package/lib/factory/bigNum.d.ts +8 -4
- package/lib/factory/bigNum.js +109 -19
- package/lib/idl/drift.json +8250 -0
- package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/lib/index.d.ts +30 -13
- package/lib/index.js +30 -13
- package/lib/math/amm.d.ts +9 -6
- package/lib/math/amm.js +91 -38
- package/lib/math/conversion.js +1 -1
- package/lib/math/exchangeStatus.d.ts +4 -0
- package/lib/math/exchangeStatus.js +18 -0
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +23 -21
- package/lib/math/insurance.d.ts +4 -0
- package/lib/math/insurance.js +27 -0
- package/lib/math/margin.d.ts +11 -0
- package/lib/math/margin.js +82 -0
- package/lib/math/market.d.ts +14 -9
- package/lib/math/market.js +70 -10
- package/lib/math/oracles.d.ts +4 -0
- package/lib/math/oracles.js +36 -8
- package/lib/math/orders.d.ts +14 -6
- package/lib/math/orders.js +90 -17
- package/lib/math/position.d.ts +27 -13
- package/lib/math/position.js +92 -36
- package/lib/math/repeg.js +17 -8
- package/lib/math/spotBalance.d.ts +22 -0
- package/lib/math/spotBalance.js +192 -0
- package/lib/math/spotMarket.d.ts +4 -0
- package/lib/math/spotMarket.js +8 -0
- package/lib/math/spotPosition.d.ts +6 -0
- package/lib/math/spotPosition.js +23 -0
- package/lib/math/trade.d.ts +10 -10
- package/lib/math/trade.js +27 -31
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/quoteAssetOracleClient.js +1 -1
- package/lib/oracles/switchboardClient.js +1 -1
- package/lib/orderParams.d.ts +4 -4
- package/lib/orderParams.js +12 -4
- package/lib/serum/serumFulfillmentConfigMap.d.ts +10 -0
- package/lib/serum/serumFulfillmentConfigMap.js +17 -0
- package/lib/serum/serumSubscriber.d.ts +27 -0
- package/lib/serum/serumSubscriber.js +56 -0
- package/lib/serum/types.d.ts +11 -0
- package/lib/{clearingHouseUserConfig.js → serum/types.js} +0 -0
- package/lib/slot/SlotSubscriber.d.ts +7 -0
- package/lib/slot/SlotSubscriber.js +3 -0
- package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +8 -5
- package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +63 -51
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +13 -4
- package/lib/tx/types.d.ts +1 -1
- package/lib/tx/utils.js +1 -1
- package/lib/types.d.ts +589 -196
- package/lib/types.js +108 -17
- package/lib/user.d.ts +226 -0
- package/lib/user.js +949 -0
- package/lib/userConfig.d.ts +14 -0
- package/lib/userConfig.js +2 -0
- package/lib/userMap/userMap.d.ts +41 -0
- package/lib/userMap/userMap.js +85 -0
- package/lib/userMap/userStatsMap.d.ts +19 -0
- package/lib/userMap/userStatsMap.js +68 -0
- package/lib/userName.d.ts +1 -0
- package/lib/userName.js +3 -2
- package/lib/userStats.d.ts +18 -0
- package/lib/userStats.js +49 -0
- package/lib/userStatsConfig.d.ts +14 -0
- package/lib/userStatsConfig.js +2 -0
- package/lib/util/computeUnits.js +1 -1
- package/lib/util/getTokenAddress.d.ts +2 -0
- package/lib/util/getTokenAddress.js +9 -0
- package/package.json +10 -3
- package/src/accounts/bulkAccountLoader.ts +44 -34
- package/src/accounts/bulkUserStatsSubscription.ts +33 -0
- package/src/accounts/bulkUserSubscription.ts +2 -3
- package/src/accounts/fetch.ts +27 -2
- package/src/accounts/{pollingClearingHouseAccountSubscriber.ts → pollingDriftClientAccountSubscriber.ts} +65 -75
- package/src/accounts/{pollingOracleSubscriber.ts → pollingOracleAccountSubscriber.ts} +2 -2
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +172 -0
- package/src/accounts/types.ts +35 -15
- package/src/accounts/{webSocketClearingHouseAccountSubscriber.ts → webSocketDriftClientAccountSubscriber.ts} +78 -73
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +80 -0
- package/src/addresses/marketAddresses.ts +3 -4
- package/src/addresses/pda.ts +105 -33
- package/src/adminClient.ts +1207 -0
- package/src/config.ts +37 -31
- package/src/constants/numericConstants.ts +58 -24
- package/src/constants/{markets.ts → perpMarkets.ts} +10 -10
- package/src/constants/spotMarkets.ts +73 -0
- package/src/dlob/DLOB.ts +1123 -0
- package/src/dlob/DLOBNode.ts +155 -0
- package/src/dlob/NodeList.ts +195 -0
- package/src/driftClient.ts +3564 -0
- package/src/{clearingHouseConfig.ts → driftClientConfig.ts} +9 -8
- package/src/events/eventList.ts +3 -0
- package/src/events/eventSubscriber.ts +36 -14
- package/src/events/fetchLogs.ts +55 -13
- package/src/events/pollingLogProvider.ts +11 -3
- package/src/events/sort.ts +11 -15
- package/src/events/types.ts +21 -2
- package/src/events/webSocketLogProvider.ts +1 -1
- package/src/examples/makeTradeExample.ts +44 -28
- package/src/factory/bigNum.ts +150 -22
- package/src/idl/drift.json +8250 -0
- package/src/idl/pyth.json +98 -2
- package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/src/index.ts +30 -13
- package/src/math/amm.ts +161 -48
- package/src/math/conversion.ts +2 -2
- package/src/math/exchangeStatus.ts +31 -0
- package/src/math/funding.ts +41 -31
- package/src/math/insurance.ts +35 -0
- package/src/math/margin.ts +133 -0
- package/src/math/market.ts +143 -14
- package/src/math/oracles.ts +63 -9
- package/src/math/orders.ts +163 -26
- package/src/math/position.ts +136 -58
- package/src/math/repeg.ts +19 -9
- package/src/math/spotBalance.ts +319 -0
- package/src/math/spotMarket.ts +9 -0
- package/src/math/spotPosition.ts +47 -0
- package/src/math/trade.ts +33 -37
- package/src/oracles/pythClient.ts +2 -2
- package/src/oracles/quoteAssetOracleClient.ts +2 -2
- package/src/oracles/switchboardClient.ts +2 -2
- package/src/orderParams.ts +16 -8
- package/src/serum/serumFulfillmentConfigMap.ts +26 -0
- package/src/serum/serumSubscriber.ts +99 -0
- package/src/serum/types.ts +13 -0
- package/src/slot/SlotSubscriber.ts +11 -1
- package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +82 -70
- package/src/tx/retryTxSender.ts +16 -5
- package/src/tx/types.ts +2 -1
- package/src/tx/utils.ts +1 -1
- package/src/types.ts +572 -178
- package/src/user.ts +1582 -0
- package/src/{clearingHouseUserConfig.ts → userConfig.ts} +5 -5
- package/src/userMap/userMap.ts +124 -0
- package/src/userMap/userStatsMap.ts +108 -0
- package/src/userName.ts +2 -1
- package/src/userStats.ts +75 -0
- package/src/userStatsConfig.ts +18 -0
- package/src/util/computeUnits.ts +1 -1
- package/src/util/getTokenAddress.ts +18 -0
- package/tests/bn/test.ts +46 -11
- package/tests/dlob/helpers.ts +611 -0
- package/tests/dlob/test.ts +4588 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +0 -49
- package/lib/admin.d.ts +0 -44
- package/lib/admin.js +0 -433
- package/lib/clearingHouse.d.ts +0 -133
- package/lib/clearingHouse.js +0 -931
- package/lib/clearingHouseUser.d.ts +0 -187
- package/lib/clearingHouseUser.js +0 -643
- package/lib/clearingHouseUserConfig.d.ts +0 -14
- package/lib/constants/banks.d.ts +0 -16
- package/lib/constants/banks.js +0 -34
- package/lib/constants/markets.d.ts +0 -19
- package/lib/idl/clearing_house.json +0 -3998
- package/lib/math/bankBalance.d.ts +0 -9
- package/lib/math/bankBalance.js +0 -75
- package/lib/math/state.d.ts +0 -8
- package/lib/math/state.js +0 -15
- package/lib/orders.d.ts +0 -8
- package/lib/orders.js +0 -134
- package/src/admin.ts +0 -722
- package/src/clearingHouse.ts +0 -1451
- package/src/clearingHouseUser.ts +0 -989
- package/src/constants/banks.ts +0 -43
- package/src/idl/clearing_house.json +0 -3998
- package/src/math/bankBalance.ts +0 -112
- package/src/math/state.ts +0 -14
- package/src/math/utils.js +0 -27
- package/src/math/utils.js.map +0 -1
- package/src/orders.ts +0 -244
- package/src/util/computeUnits.js +0 -17
- package/src/util/computeUnits.js.map +0 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
|
|
3
|
+
export declare type SerumMarketSubscriberConfig = {
|
|
4
|
+
connection: Connection;
|
|
5
|
+
programId: PublicKey;
|
|
6
|
+
marketAddress: PublicKey;
|
|
7
|
+
accountSubscription: {
|
|
8
|
+
type: 'polling';
|
|
9
|
+
accountLoader: BulkAccountLoader;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
File without changes
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Connection } from '@solana/web3.js';
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
|
+
import StrictEventEmitter from 'strict-event-emitter-types/types/src';
|
|
2
5
|
declare type SlotSubscriberConfig = {};
|
|
6
|
+
export interface SlotSubscriberEvents {
|
|
7
|
+
newSlot: (newSlot: number) => void;
|
|
8
|
+
}
|
|
3
9
|
export declare class SlotSubscriber {
|
|
4
10
|
private connection;
|
|
5
11
|
currentSlot: number;
|
|
6
12
|
subscriptionId: number;
|
|
13
|
+
eventEmitter: StrictEventEmitter<EventEmitter, SlotSubscriberEvents>;
|
|
7
14
|
constructor(connection: Connection, _config?: SlotSubscriberConfig);
|
|
8
15
|
subscribe(): Promise<void>;
|
|
9
16
|
getSlot(): number;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SlotSubscriber = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
4
5
|
class SlotSubscriber {
|
|
5
6
|
constructor(connection, _config) {
|
|
6
7
|
this.connection = connection;
|
|
8
|
+
this.eventEmitter = new events_1.EventEmitter();
|
|
7
9
|
}
|
|
8
10
|
async subscribe() {
|
|
9
11
|
this.currentSlot = await this.connection.getSlot('confirmed');
|
|
10
12
|
this.subscriptionId = this.connection.onSlotChange((slotInfo) => {
|
|
11
13
|
this.currentSlot = slotInfo.slot;
|
|
14
|
+
this.eventEmitter.emit('newSlot', slotInfo.slot);
|
|
12
15
|
});
|
|
13
16
|
}
|
|
14
17
|
getSlot() {
|
|
@@ -5,22 +5,25 @@ import { AccountInfo } from '@solana/spl-token';
|
|
|
5
5
|
import { ConfirmOptions, Connection, PublicKey, TransactionInstruction, TransactionSignature } from '@solana/web3.js';
|
|
6
6
|
import { BN } from '.';
|
|
7
7
|
import { IWallet } from './types';
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class TokenFaucet {
|
|
9
9
|
connection: Connection;
|
|
10
10
|
wallet: IWallet;
|
|
11
11
|
program: Program;
|
|
12
12
|
provider: AnchorProvider;
|
|
13
|
+
mint: PublicKey;
|
|
13
14
|
opts?: ConfirmOptions;
|
|
14
|
-
constructor(connection: Connection, wallet: IWallet, programId: PublicKey, opts?: ConfirmOptions);
|
|
15
|
-
|
|
15
|
+
constructor(connection: Connection, wallet: IWallet, programId: PublicKey, mint: PublicKey, opts?: ConfirmOptions);
|
|
16
|
+
getFaucetConfigPublicKeyAndNonce(): Promise<[
|
|
16
17
|
PublicKey,
|
|
17
18
|
number
|
|
18
19
|
]>;
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
getMintAuthority(): Promise<PublicKey>;
|
|
21
|
+
getFaucetConfigPublicKey(): Promise<PublicKey>;
|
|
21
22
|
initialize(): Promise<TransactionSignature>;
|
|
22
23
|
fetchState(): Promise<any>;
|
|
24
|
+
private mintToUserIx;
|
|
23
25
|
mintToUser(userTokenAccount: PublicKey, amount: BN): Promise<TransactionSignature>;
|
|
26
|
+
transferMintAuthority(): Promise<TransactionSignature>;
|
|
24
27
|
createAssociatedTokenAccountAndMintTo(userPublicKey: PublicKey, amount: BN): Promise<[PublicKey, TransactionSignature]>;
|
|
25
28
|
createAssociatedTokenAccountAndMintToInstructions(userPublicKey: PublicKey, amount: BN): Promise<[PublicKey, TransactionInstruction, TransactionInstruction]>;
|
|
26
29
|
getAssosciatedMockUSDMintAddress(props: {
|
|
@@ -26,77 +26,97 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
29
|
+
exports.TokenFaucet = void 0;
|
|
30
30
|
const anchor = __importStar(require("@project-serum/anchor"));
|
|
31
31
|
const anchor_1 = require("@project-serum/anchor");
|
|
32
32
|
const spl_token_1 = require("@solana/spl-token");
|
|
33
33
|
const web3_js_1 = require("@solana/web3.js");
|
|
34
|
-
const
|
|
35
|
-
class
|
|
36
|
-
constructor(connection, wallet, programId, opts) {
|
|
34
|
+
const token_faucet_json_1 = __importDefault(require("./idl/token_faucet.json"));
|
|
35
|
+
class TokenFaucet {
|
|
36
|
+
constructor(connection, wallet, programId, mint, opts) {
|
|
37
37
|
this.connection = connection;
|
|
38
38
|
this.wallet = wallet;
|
|
39
39
|
this.opts = opts || anchor_1.AnchorProvider.defaultOptions();
|
|
40
40
|
const provider = new anchor_1.AnchorProvider(connection, wallet, this.opts);
|
|
41
41
|
this.provider = provider;
|
|
42
|
-
this.program = new anchor_1.Program(
|
|
42
|
+
this.program = new anchor_1.Program(token_faucet_json_1.default, programId, provider);
|
|
43
|
+
this.mint = mint;
|
|
43
44
|
}
|
|
44
|
-
async
|
|
45
|
-
return anchor.web3.PublicKey.findProgramAddress([
|
|
45
|
+
async getFaucetConfigPublicKeyAndNonce() {
|
|
46
|
+
return anchor.web3.PublicKey.findProgramAddress([
|
|
47
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('faucet_config')),
|
|
48
|
+
this.mint.toBuffer(),
|
|
49
|
+
], this.program.programId);
|
|
46
50
|
}
|
|
47
|
-
async
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
async getMintAuthority() {
|
|
52
|
+
return (await anchor.web3.PublicKey.findProgramAddress([
|
|
53
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('mint_authority')),
|
|
54
|
+
this.mint.toBuffer(),
|
|
55
|
+
], this.program.programId))[0];
|
|
56
|
+
}
|
|
57
|
+
async getFaucetConfigPublicKey() {
|
|
58
|
+
return (await this.getFaucetConfigPublicKeyAndNonce())[0];
|
|
53
59
|
}
|
|
54
60
|
async initialize() {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
throw new Error('Faucet already initialized');
|
|
58
|
-
}
|
|
59
|
-
const fakeUSDCMint = anchor.web3.Keypair.generate();
|
|
60
|
-
const createUSDCMintAccountIx = web3_js_1.SystemProgram.createAccount({
|
|
61
|
-
fromPubkey: this.wallet.publicKey,
|
|
62
|
-
newAccountPubkey: fakeUSDCMint.publicKey,
|
|
63
|
-
lamports: await spl_token_1.Token.getMinBalanceRentForExemptMint(this.connection),
|
|
64
|
-
space: spl_token_1.MintLayout.span,
|
|
65
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
66
|
-
});
|
|
67
|
-
const [mintAuthority, _mintAuthorityNonce] = await web3_js_1.PublicKey.findProgramAddress([fakeUSDCMint.publicKey.toBuffer()], this.program.programId);
|
|
68
|
-
const initUSDCMintIx = spl_token_1.Token.createInitMintInstruction(spl_token_1.TOKEN_PROGRAM_ID, fakeUSDCMint.publicKey, 6, mintAuthority, null);
|
|
69
|
-
const [mockUSDCFaucetStatePublicKey, mockUSDCFaucetStateNonce] = await this.getMockUSDCFaucetStatePublicKeyAndNonce();
|
|
70
|
-
return await this.program.rpc.initialize(mockUSDCFaucetStateNonce, {
|
|
61
|
+
const [faucetConfigPublicKey] = await this.getFaucetConfigPublicKeyAndNonce();
|
|
62
|
+
return await this.program.rpc.initialize({
|
|
71
63
|
accounts: {
|
|
72
|
-
|
|
64
|
+
faucetConfig: faucetConfigPublicKey,
|
|
73
65
|
admin: this.wallet.publicKey,
|
|
74
|
-
mintAccount:
|
|
66
|
+
mintAccount: this.mint,
|
|
75
67
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
76
68
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
69
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
77
70
|
},
|
|
78
|
-
instructions: [createUSDCMintAccountIx, initUSDCMintIx],
|
|
79
|
-
signers: [fakeUSDCMint],
|
|
80
71
|
});
|
|
81
72
|
}
|
|
82
73
|
async fetchState() {
|
|
83
|
-
return await this.program.account.
|
|
74
|
+
return await this.program.account.faucetConfig.fetch(await this.getFaucetConfigPublicKey());
|
|
84
75
|
}
|
|
85
|
-
async
|
|
86
|
-
|
|
87
|
-
return await this.program.rpc.mintToUser(amount, {
|
|
76
|
+
async mintToUserIx(userTokenAccount, amount) {
|
|
77
|
+
return this.program.instruction.mintToUser(amount, {
|
|
88
78
|
accounts: {
|
|
89
|
-
|
|
90
|
-
mintAccount:
|
|
79
|
+
faucetConfig: await this.getFaucetConfigPublicKey(),
|
|
80
|
+
mintAccount: this.mint,
|
|
91
81
|
userTokenAccount,
|
|
92
|
-
mintAuthority:
|
|
82
|
+
mintAuthority: await this.getMintAuthority(),
|
|
83
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async mintToUser(userTokenAccount, amount) {
|
|
88
|
+
const mintIx = await this.mintToUserIx(userTokenAccount, amount);
|
|
89
|
+
const tx = new web3_js_1.Transaction().add(mintIx);
|
|
90
|
+
const txSig = await this.program.provider.sendAndConfirm(tx, [], this.opts);
|
|
91
|
+
return txSig;
|
|
92
|
+
}
|
|
93
|
+
async transferMintAuthority() {
|
|
94
|
+
return await this.program.rpc.transferMintAuthority({
|
|
95
|
+
accounts: {
|
|
96
|
+
faucetConfig: await this.getFaucetConfigPublicKey(),
|
|
97
|
+
mintAccount: this.mint,
|
|
98
|
+
mintAuthority: await this.getMintAuthority(),
|
|
93
99
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
100
|
+
admin: this.wallet.publicKey,
|
|
94
101
|
},
|
|
95
102
|
});
|
|
96
103
|
}
|
|
97
104
|
async createAssociatedTokenAccountAndMintTo(userPublicKey, amount) {
|
|
105
|
+
const tx = new web3_js_1.Transaction();
|
|
98
106
|
const [associatedTokenPublicKey, createAssociatedAccountIx, mintToTx] = await this.createAssociatedTokenAccountAndMintToInstructions(userPublicKey, amount);
|
|
99
|
-
|
|
107
|
+
let associatedTokenAccountExists = false;
|
|
108
|
+
try {
|
|
109
|
+
const assosciatedTokenAccount = await this.connection.getAccountInfo(associatedTokenPublicKey);
|
|
110
|
+
associatedTokenAccountExists = !!assosciatedTokenAccount;
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
// token account doesn't exist
|
|
114
|
+
associatedTokenAccountExists = false;
|
|
115
|
+
}
|
|
116
|
+
const skipAccountCreation = associatedTokenAccountExists;
|
|
117
|
+
if (!skipAccountCreation)
|
|
118
|
+
tx.add(createAssociatedAccountIx);
|
|
119
|
+
tx.add(mintToTx);
|
|
100
120
|
const txSig = await this.program.provider.sendAndConfirm(tx, [], this.opts);
|
|
101
121
|
return [associatedTokenPublicKey, txSig];
|
|
102
122
|
}
|
|
@@ -104,15 +124,7 @@ class MockUSDCFaucet {
|
|
|
104
124
|
const state = await this.fetchState();
|
|
105
125
|
const associateTokenPublicKey = await this.getAssosciatedMockUSDMintAddress({ userPubKey: userPublicKey });
|
|
106
126
|
const createAssociatedAccountIx = spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, state.mint, associateTokenPublicKey, userPublicKey, this.wallet.publicKey);
|
|
107
|
-
const mintToIx = await this.
|
|
108
|
-
accounts: {
|
|
109
|
-
mockUsdcFaucetState: await this.getMockUSDCFaucetStatePublicKey(),
|
|
110
|
-
mintAccount: state.mint,
|
|
111
|
-
userTokenAccount: associateTokenPublicKey,
|
|
112
|
-
mintAuthority: state.mintAuthority,
|
|
113
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
114
|
-
},
|
|
115
|
-
});
|
|
127
|
+
const mintToIx = await this.mintToUserIx(associateTokenPublicKey, amount);
|
|
116
128
|
return [associateTokenPublicKey, createAssociatedAccountIx, mintToIx];
|
|
117
129
|
}
|
|
118
130
|
async getAssosciatedMockUSDMintAddress(props) {
|
|
@@ -143,4 +155,4 @@ class MockUSDCFaucet {
|
|
|
143
155
|
}
|
|
144
156
|
}
|
|
145
157
|
}
|
|
146
|
-
exports.
|
|
158
|
+
exports.TokenFaucet = TokenFaucet;
|
|
@@ -11,7 +11,7 @@ export declare class RetryTxSender implements TxSender {
|
|
|
11
11
|
retrySleep: number;
|
|
12
12
|
additionalConnections: Connection[];
|
|
13
13
|
constructor(provider: AnchorProvider, timeout?: number, retrySleep?: number, additionalConnections?: Connection[]);
|
|
14
|
-
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<TxSigAndSlot>;
|
|
14
|
+
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
|
|
15
15
|
prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions): Promise<Transaction>;
|
|
16
16
|
confirmTransaction(signature: TransactionSignature, commitment?: Commitment): Promise<RpcResponseAndContext<SignatureResult>>;
|
|
17
17
|
getTimestamp(): number;
|
package/lib/tx/retryTxSender.js
CHANGED
|
@@ -15,18 +15,27 @@ class RetryTxSender {
|
|
|
15
15
|
this.retrySleep = retrySleep !== null && retrySleep !== void 0 ? retrySleep : DEFAULT_RETRY;
|
|
16
16
|
this.additionalConnections = additionalConnections;
|
|
17
17
|
}
|
|
18
|
-
async send(tx, additionalSigners, opts) {
|
|
18
|
+
async send(tx, additionalSigners, opts, preSigned) {
|
|
19
19
|
if (additionalSigners === undefined) {
|
|
20
20
|
additionalSigners = [];
|
|
21
21
|
}
|
|
22
22
|
if (opts === undefined) {
|
|
23
23
|
opts = this.provider.opts;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
if (!preSigned) {
|
|
26
|
+
await this.prepareTx(tx, additionalSigners, opts);
|
|
27
|
+
}
|
|
26
28
|
const rawTransaction = tx.serialize();
|
|
27
29
|
const startTime = this.getTimestamp();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
let txid;
|
|
31
|
+
try {
|
|
32
|
+
txid = await this.provider.connection.sendRawTransaction(rawTransaction, opts);
|
|
33
|
+
this.sendToAdditionalConnections(rawTransaction, opts);
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
console.error(e);
|
|
37
|
+
throw e;
|
|
38
|
+
}
|
|
30
39
|
let done = false;
|
|
31
40
|
const resolveReference = {
|
|
32
41
|
resolve: undefined,
|
package/lib/tx/types.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export declare type TxSigAndSlot = {
|
|
|
6
6
|
};
|
|
7
7
|
export interface TxSender {
|
|
8
8
|
provider: Provider;
|
|
9
|
-
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<TxSigAndSlot>;
|
|
9
|
+
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
|
|
10
10
|
}
|
package/lib/tx/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.wrapInTx = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
const COMPUTE_UNITS_DEFAULT = 200000;
|
|
6
|
-
function wrapInTx(instruction, computeUnits =
|
|
6
|
+
function wrapInTx(instruction, computeUnits = 600000 // TODO, requires less code change
|
|
7
7
|
) {
|
|
8
8
|
const tx = new web3_js_1.Transaction();
|
|
9
9
|
if (computeUnits != COMPUTE_UNITS_DEFAULT) {
|