@streamflow/stream 3.0.16 → 4.0.0-Alpha.0
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/StreamClient.d.ts +3 -4
- package/dist/StreamClient.js +35 -21
- package/dist/__tests__/aptos/streamClient.spec.d.ts +1 -0
- package/dist/__tests__/aptos/streamClient.spec.js +160 -0
- package/dist/__tests__/test_dependencies/airdrop/airdrop-request.d.ts +0 -1
- package/dist/aptos/StreamClient.d.ts +19 -0
- package/dist/aptos/StreamClient.js +296 -0
- package/dist/aptos/constants.d.ts +2 -0
- package/dist/aptos/constants.js +12 -0
- package/dist/aptos/index.d.ts +2 -0
- package/dist/aptos/index.js +23 -0
- package/dist/aptos/types.d.ts +10 -0
- package/dist/aptos/types.js +2 -0
- package/dist/common/types.d.ts +70 -0
- package/dist/common/types.js +29 -0
- package/dist/common/utils.d.ts +15 -0
- package/dist/common/utils.js +31 -0
- package/dist/index.d.ts +4 -6
- package/dist/index.js +17 -13
- package/dist/instructionTypes.d.ts +81 -0
- package/dist/instructionTypes.js +2 -0
- package/dist/instructions.d.ts +0 -2
- package/dist/instructions.js +18 -29
- package/dist/layout.d.ts +7 -7
- package/dist/layout.js +78 -75
- package/dist/solana/StreamClient.d.ts +145 -0
- package/dist/solana/StreamClient.js +952 -0
- package/dist/solana/constants.d.ts +18 -0
- package/dist/solana/constants.js +23 -0
- package/dist/solana/index.d.ts +5 -0
- package/dist/solana/index.js +27 -0
- package/dist/solana/instructionTypes.d.ts +81 -0
- package/dist/solana/instructionTypes.js +2 -0
- package/dist/solana/instructions.d.ts +131 -0
- package/dist/solana/instructions.js +375 -0
- package/dist/solana/layout.d.ts +22 -0
- package/dist/solana/layout.js +96 -0
- package/dist/solana/timelockIDL.d.ts +22 -0
- package/dist/solana/timelockIDL.js +422 -0
- package/dist/solana/types.d.ts +321 -0
- package/dist/solana/types.js +74 -0
- package/dist/solana/utils.d.ts +42 -0
- package/dist/solana/utils.js +269 -0
- package/dist/types.d.ts +12 -13
- package/package.json +23 -10
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
export declare const TX_FINALITY_CONFIRMED = "confirmed";
|
|
3
|
+
export declare const STREAM_STRUCT_OFFSET_SENDER = 49;
|
|
4
|
+
export declare const STREAM_STRUCT_OFFSET_RECIPIENT = 113;
|
|
5
|
+
export declare const PROGRAM_ID: {
|
|
6
|
+
devnet: string;
|
|
7
|
+
mainnet: string;
|
|
8
|
+
testnet: string;
|
|
9
|
+
local: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const STREAMFLOW_PROGRAM_ID = "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m";
|
|
12
|
+
export declare const STREAMFLOW_DEVNET_PROGRAM_ID = "FGjLaVo5zLGdzCxMo9gu9tXr1kzTToKd8C8K7YS5hNM1";
|
|
13
|
+
export declare const STREAMFLOW_TREASURY_PUBLIC_KEY: PublicKey;
|
|
14
|
+
export declare const WITHDRAWOR_PUBLIC_KEY: PublicKey;
|
|
15
|
+
export declare const FEE_ORACLE_PUBLIC_KEY: PublicKey;
|
|
16
|
+
export declare const AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
|
|
17
|
+
export declare const AIRDROP_AMOUNT = 1;
|
|
18
|
+
export declare const BASE_FEE = 1002500;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.BASE_FEE = exports.AIRDROP_AMOUNT = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.STREAMFLOW_DEVNET_PROGRAM_ID = exports.STREAMFLOW_PROGRAM_ID = exports.PROGRAM_ID = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
|
|
5
|
+
var web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
var types_1 = require("../common/types");
|
|
7
|
+
exports.TX_FINALITY_CONFIRMED = "confirmed";
|
|
8
|
+
exports.STREAM_STRUCT_OFFSET_SENDER = 49;
|
|
9
|
+
exports.STREAM_STRUCT_OFFSET_RECIPIENT = 113;
|
|
10
|
+
exports.PROGRAM_ID = (_a = {},
|
|
11
|
+
_a[types_1.ICluster.Devnet] = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
|
|
12
|
+
_a[types_1.ICluster.Mainnet] = "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m",
|
|
13
|
+
_a[types_1.ICluster.Testnet] = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
|
|
14
|
+
_a[types_1.ICluster.Local] = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
|
|
15
|
+
_a);
|
|
16
|
+
exports.STREAMFLOW_PROGRAM_ID = "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m";
|
|
17
|
+
exports.STREAMFLOW_DEVNET_PROGRAM_ID = "FGjLaVo5zLGdzCxMo9gu9tXr1kzTToKd8C8K7YS5hNM1";
|
|
18
|
+
exports.STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js_1.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
|
|
19
|
+
exports.WITHDRAWOR_PUBLIC_KEY = new web3_js_1.PublicKey("wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u");
|
|
20
|
+
exports.FEE_ORACLE_PUBLIC_KEY = new web3_js_1.PublicKey("B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT");
|
|
21
|
+
exports.AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
|
|
22
|
+
exports.AIRDROP_AMOUNT = 1; // 1 SOL is the cap on the testnet
|
|
23
|
+
exports.BASE_FEE = 1002500; // Basic buffer for intermediary swaps
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.BN = exports.default = void 0;
|
|
21
|
+
var StreamClient_1 = require("./StreamClient");
|
|
22
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
|
|
23
|
+
__exportStar(require("./utils"), exports);
|
|
24
|
+
__exportStar(require("./types"), exports);
|
|
25
|
+
__exportStar(require("./instructions"), exports);
|
|
26
|
+
var bn_js_1 = require("bn.js");
|
|
27
|
+
Object.defineProperty(exports, "BN", { enumerable: true, get: function () { return __importDefault(bn_js_1).default; } });
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export interface IStreamLayout {
|
|
2
|
+
magic: Uint8Array;
|
|
3
|
+
version: Uint8Array;
|
|
4
|
+
created_at: Uint8Array;
|
|
5
|
+
withdrawn_amount: Uint8Array;
|
|
6
|
+
canceled_at: Uint8Array;
|
|
7
|
+
end_time: Uint8Array;
|
|
8
|
+
last_withdrawn_at: Uint8Array;
|
|
9
|
+
sender: Uint8Array;
|
|
10
|
+
sender_tokens: Uint8Array;
|
|
11
|
+
recipient: Uint8Array;
|
|
12
|
+
recipient_tokens: Uint8Array;
|
|
13
|
+
mint: Uint8Array;
|
|
14
|
+
escrow_tokens: Uint8Array;
|
|
15
|
+
streamflow_treasury: Uint8Array;
|
|
16
|
+
streamflow_treasury_tokens: Uint8Array;
|
|
17
|
+
streamflow_fee_total: Uint8Array;
|
|
18
|
+
streamflow_fee_withdrawn: Uint8Array;
|
|
19
|
+
streamflow_fee_percent: number;
|
|
20
|
+
partner: Uint8Array;
|
|
21
|
+
partner_tokens: Uint8Array;
|
|
22
|
+
partner_fee_total: Uint8Array;
|
|
23
|
+
partner_fee_withdrawn: Uint8Array;
|
|
24
|
+
partner_fee_percent: number;
|
|
25
|
+
start_time: Uint8Array;
|
|
26
|
+
net_amount_deposited: Uint8Array;
|
|
27
|
+
period: Uint8Array;
|
|
28
|
+
amount_per_period: Uint8Array;
|
|
29
|
+
cliff: Uint8Array;
|
|
30
|
+
cliff_amount: Uint8Array;
|
|
31
|
+
cancelable_by_sender: number;
|
|
32
|
+
cancelable_by_recipient: number;
|
|
33
|
+
automatic_withdrawal: number;
|
|
34
|
+
transferable_by_sender: number;
|
|
35
|
+
transferable_by_recipient: number;
|
|
36
|
+
can_topup: number;
|
|
37
|
+
stream_name: Uint8Array;
|
|
38
|
+
withdraw_frequency: Uint8Array;
|
|
39
|
+
}
|
|
40
|
+
export interface ICreateStreamLayout {
|
|
41
|
+
start_time: Uint8Array;
|
|
42
|
+
net_amount_deposited: Uint8Array;
|
|
43
|
+
period: Uint8Array;
|
|
44
|
+
amount_per_period: Uint8Array;
|
|
45
|
+
cliff: Uint8Array;
|
|
46
|
+
cliff_amount: Uint8Array;
|
|
47
|
+
cancelable_by_sender: number;
|
|
48
|
+
cancelable_by_recipient: number;
|
|
49
|
+
automatic_withdrawal: number;
|
|
50
|
+
transferable_by_sender: number;
|
|
51
|
+
transferable_by_recipient: number;
|
|
52
|
+
can_topup: number;
|
|
53
|
+
stream_name: Uint8Array;
|
|
54
|
+
withdraw_frequency: Uint8Array;
|
|
55
|
+
}
|
|
56
|
+
export interface ICreateUncheckedStreamLayout {
|
|
57
|
+
start_time: Uint8Array;
|
|
58
|
+
net_amount_deposited: Uint8Array;
|
|
59
|
+
period: Uint8Array;
|
|
60
|
+
amount_per_period: Uint8Array;
|
|
61
|
+
cliff: Uint8Array;
|
|
62
|
+
cliff_amount: Uint8Array;
|
|
63
|
+
cancelable_by_sender: number;
|
|
64
|
+
cancelable_by_recipient: number;
|
|
65
|
+
automatic_withdrawal: number;
|
|
66
|
+
transferable_by_sender: number;
|
|
67
|
+
transferable_by_recipient: number;
|
|
68
|
+
can_topup: number;
|
|
69
|
+
stream_name: Uint8Array;
|
|
70
|
+
withdraw_frequency: Uint8Array;
|
|
71
|
+
recipient: Uint8Array;
|
|
72
|
+
partner: Uint8Array;
|
|
73
|
+
pausable: number;
|
|
74
|
+
can_update_rate: number;
|
|
75
|
+
}
|
|
76
|
+
export interface IWithdrawStreamLayout {
|
|
77
|
+
amount: Uint8Array;
|
|
78
|
+
}
|
|
79
|
+
export interface ITopupStreamLayout {
|
|
80
|
+
amount: Uint8Array;
|
|
81
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import BN from "bn.js";
|
|
3
|
+
interface CreateStreamData {
|
|
4
|
+
start: BN;
|
|
5
|
+
depositedAmount: BN;
|
|
6
|
+
period: BN;
|
|
7
|
+
amountPerPeriod: BN;
|
|
8
|
+
cliff: BN;
|
|
9
|
+
cliffAmount: BN;
|
|
10
|
+
cancelableBySender: boolean;
|
|
11
|
+
cancelableByRecipient: boolean;
|
|
12
|
+
automaticWithdrawal: boolean;
|
|
13
|
+
transferableBySender: boolean;
|
|
14
|
+
transferableByRecipient: boolean;
|
|
15
|
+
canTopup: boolean;
|
|
16
|
+
name: string;
|
|
17
|
+
withdrawFrequency: BN;
|
|
18
|
+
}
|
|
19
|
+
interface CreateStreamAccounts {
|
|
20
|
+
sender: PublicKey;
|
|
21
|
+
senderTokens: PublicKey;
|
|
22
|
+
recipient: PublicKey;
|
|
23
|
+
recipientTokens: PublicKey;
|
|
24
|
+
metadata: PublicKey;
|
|
25
|
+
escrowTokens: PublicKey;
|
|
26
|
+
streamflowTreasury: PublicKey;
|
|
27
|
+
streamflowTreasuryTokens: PublicKey;
|
|
28
|
+
partner: PublicKey;
|
|
29
|
+
partnerTokens: PublicKey;
|
|
30
|
+
mint: PublicKey;
|
|
31
|
+
feeOracle: PublicKey;
|
|
32
|
+
rent: PublicKey;
|
|
33
|
+
timelockProgram: PublicKey;
|
|
34
|
+
tokenProgram: PublicKey;
|
|
35
|
+
associatedTokenProgram: PublicKey;
|
|
36
|
+
withdrawor: PublicKey;
|
|
37
|
+
systemProgram: PublicKey;
|
|
38
|
+
}
|
|
39
|
+
export declare const createStreamInstruction: (data: CreateStreamData, programId: PublicKey, accounts: CreateStreamAccounts) => TransactionInstruction;
|
|
40
|
+
interface CreateUncheckedStreamData {
|
|
41
|
+
start: BN;
|
|
42
|
+
depositedAmount: BN;
|
|
43
|
+
period: BN;
|
|
44
|
+
amountPerPeriod: BN;
|
|
45
|
+
cliff: BN;
|
|
46
|
+
cliffAmount: BN;
|
|
47
|
+
cancelableBySender: boolean;
|
|
48
|
+
cancelableByRecipient: boolean;
|
|
49
|
+
automaticWithdrawal: boolean;
|
|
50
|
+
transferableBySender: boolean;
|
|
51
|
+
transferableByRecipient: boolean;
|
|
52
|
+
canTopup: boolean;
|
|
53
|
+
name: string;
|
|
54
|
+
withdrawFrequency: BN;
|
|
55
|
+
recipient: PublicKey;
|
|
56
|
+
partner: PublicKey;
|
|
57
|
+
}
|
|
58
|
+
interface CreateUncheckedStreamAccounts {
|
|
59
|
+
payer?: PublicKey;
|
|
60
|
+
sender: PublicKey;
|
|
61
|
+
senderTokens: PublicKey;
|
|
62
|
+
metadata: PublicKey;
|
|
63
|
+
escrowTokens: PublicKey;
|
|
64
|
+
mint: PublicKey;
|
|
65
|
+
feeOracle: PublicKey;
|
|
66
|
+
rent: PublicKey;
|
|
67
|
+
timelockProgram: PublicKey;
|
|
68
|
+
tokenProgram: PublicKey;
|
|
69
|
+
withdrawor: PublicKey;
|
|
70
|
+
systemProgram: PublicKey;
|
|
71
|
+
}
|
|
72
|
+
export declare const createUncheckedStreamInstruction: (data: CreateUncheckedStreamData, programId: PublicKey, accounts: CreateUncheckedStreamAccounts) => TransactionInstruction;
|
|
73
|
+
interface WithdrawAccounts {
|
|
74
|
+
authority: PublicKey;
|
|
75
|
+
recipient: PublicKey;
|
|
76
|
+
recipientTokens: PublicKey;
|
|
77
|
+
metadata: PublicKey;
|
|
78
|
+
escrowTokens: PublicKey;
|
|
79
|
+
streamflowTreasury: PublicKey;
|
|
80
|
+
streamflowTreasuryTokens: PublicKey;
|
|
81
|
+
partner: PublicKey;
|
|
82
|
+
partnerTokens: PublicKey;
|
|
83
|
+
mint: PublicKey;
|
|
84
|
+
tokenProgram: PublicKey;
|
|
85
|
+
}
|
|
86
|
+
export declare const withdrawStreamInstruction: (amount: BN, programId: PublicKey, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }: WithdrawAccounts) => TransactionInstruction;
|
|
87
|
+
interface CancelAccounts {
|
|
88
|
+
authority: PublicKey;
|
|
89
|
+
sender: PublicKey;
|
|
90
|
+
senderTokens: PublicKey;
|
|
91
|
+
recipient: PublicKey;
|
|
92
|
+
recipientTokens: PublicKey;
|
|
93
|
+
metadata: PublicKey;
|
|
94
|
+
escrowTokens: PublicKey;
|
|
95
|
+
streamflowTreasury: PublicKey;
|
|
96
|
+
streamflowTreasuryTokens: PublicKey;
|
|
97
|
+
partner: PublicKey;
|
|
98
|
+
partnerTokens: PublicKey;
|
|
99
|
+
mint: PublicKey;
|
|
100
|
+
tokenProgram: PublicKey;
|
|
101
|
+
}
|
|
102
|
+
export declare const cancelStreamInstruction: (programId: PublicKey, { authority, sender, senderTokens, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }: CancelAccounts) => TransactionInstruction;
|
|
103
|
+
interface TransferAccounts {
|
|
104
|
+
authority: PublicKey;
|
|
105
|
+
newRecipient: PublicKey;
|
|
106
|
+
newRecipientTokens: PublicKey;
|
|
107
|
+
metadata: PublicKey;
|
|
108
|
+
mint: PublicKey;
|
|
109
|
+
rent: PublicKey;
|
|
110
|
+
tokenProgram: PublicKey;
|
|
111
|
+
associatedTokenProgram: PublicKey;
|
|
112
|
+
systemProgram: PublicKey;
|
|
113
|
+
}
|
|
114
|
+
export declare const transferStreamInstruction: (programId: PublicKey, { authority, newRecipient, newRecipientTokens, metadata, mint, rent, tokenProgram, associatedTokenProgram, systemProgram, }: TransferAccounts) => TransactionInstruction;
|
|
115
|
+
interface TopupAccounts {
|
|
116
|
+
sender: PublicKey;
|
|
117
|
+
senderTokens: PublicKey;
|
|
118
|
+
metadata: PublicKey;
|
|
119
|
+
escrowTokens: PublicKey;
|
|
120
|
+
streamflowTreasury: PublicKey;
|
|
121
|
+
streamflowTreasuryTokens: PublicKey;
|
|
122
|
+
partner: PublicKey;
|
|
123
|
+
partnerTokens: PublicKey;
|
|
124
|
+
mint: PublicKey;
|
|
125
|
+
tokenProgram: PublicKey;
|
|
126
|
+
withdrawor: PublicKey;
|
|
127
|
+
systemProgram: PublicKey;
|
|
128
|
+
}
|
|
129
|
+
export declare const topupStreamInstruction: (amount: BN, programId: PublicKey, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }: TopupAccounts) => TransactionInstruction;
|
|
130
|
+
export declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount: BN) => Promise<TransactionInstruction[]>;
|
|
131
|
+
export {};
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (_) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
62
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
63
|
+
if (!m) return o;
|
|
64
|
+
var i = m.call(o), r, ar = [], e;
|
|
65
|
+
try {
|
|
66
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
67
|
+
}
|
|
68
|
+
catch (error) { e = { error: error }; }
|
|
69
|
+
finally {
|
|
70
|
+
try {
|
|
71
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
72
|
+
}
|
|
73
|
+
finally { if (e) throw e.error; }
|
|
74
|
+
}
|
|
75
|
+
return ar;
|
|
76
|
+
};
|
|
77
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
78
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
79
|
+
if (ar || !(i in from)) {
|
|
80
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
81
|
+
ar[i] = from[i];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
85
|
+
};
|
|
86
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
87
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
88
|
+
};
|
|
89
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
90
|
+
exports.prepareWrappedAccount = exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
|
|
91
|
+
var buffer_1 = require("buffer");
|
|
92
|
+
var web3_js_1 = require("@solana/web3.js");
|
|
93
|
+
var bn_js_1 = __importDefault(require("bn.js"));
|
|
94
|
+
var js_sha256_1 = require("js-sha256");
|
|
95
|
+
var spl_token_1 = require("@solana/spl-token");
|
|
96
|
+
var Layout = __importStar(require("./layout"));
|
|
97
|
+
var constants_1 = require("./constants");
|
|
98
|
+
var createStreamInstruction = function (data, programId, accounts) {
|
|
99
|
+
var keys = [
|
|
100
|
+
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
101
|
+
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
102
|
+
{ pubkey: accounts.recipient, isSigner: false, isWritable: true },
|
|
103
|
+
{ pubkey: accounts.metadata, isSigner: true, isWritable: true },
|
|
104
|
+
{ pubkey: accounts.escrowTokens, isSigner: false, isWritable: true },
|
|
105
|
+
{ pubkey: accounts.recipientTokens, isSigner: false, isWritable: true },
|
|
106
|
+
{
|
|
107
|
+
pubkey: accounts.streamflowTreasury,
|
|
108
|
+
isSigner: false,
|
|
109
|
+
isWritable: true,
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
pubkey: accounts.streamflowTreasuryTokens,
|
|
113
|
+
isSigner: false,
|
|
114
|
+
isWritable: true,
|
|
115
|
+
},
|
|
116
|
+
{ pubkey: accounts.withdrawor, isSigner: false, isWritable: true },
|
|
117
|
+
{ pubkey: accounts.partner, isSigner: false, isWritable: true },
|
|
118
|
+
{ pubkey: accounts.partnerTokens, isSigner: false, isWritable: true },
|
|
119
|
+
{ pubkey: accounts.mint, isSigner: false, isWritable: false },
|
|
120
|
+
{ pubkey: accounts.feeOracle, isSigner: false, isWritable: false },
|
|
121
|
+
{ pubkey: accounts.rent, isSigner: false, isWritable: false },
|
|
122
|
+
{ pubkey: accounts.timelockProgram, isSigner: false, isWritable: false },
|
|
123
|
+
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
124
|
+
{
|
|
125
|
+
pubkey: accounts.associatedTokenProgram,
|
|
126
|
+
isSigner: false,
|
|
127
|
+
isWritable: false,
|
|
128
|
+
},
|
|
129
|
+
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
|
|
130
|
+
];
|
|
131
|
+
var bufferData = buffer_1.Buffer.alloc(Layout.createStreamLayout.span);
|
|
132
|
+
var encodedUIntArray = new TextEncoder().encode(data.name);
|
|
133
|
+
var streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
134
|
+
var decodedData = {
|
|
135
|
+
start_time: data.start.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
136
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
137
|
+
period: data.period.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
138
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
139
|
+
cliff: data.cliff.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
140
|
+
cliff_amount: data.cliffAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
141
|
+
cancelable_by_sender: Number(data.cancelableBySender),
|
|
142
|
+
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
143
|
+
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
144
|
+
transferable_by_sender: Number(data.transferableBySender),
|
|
145
|
+
transferable_by_recipient: Number(data.transferableByRecipient),
|
|
146
|
+
can_topup: Number(data.canTopup),
|
|
147
|
+
stream_name: streamNameBuffer,
|
|
148
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
149
|
+
};
|
|
150
|
+
var encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
|
|
151
|
+
bufferData = bufferData.slice(0, encodeLength);
|
|
152
|
+
bufferData = buffer_1.Buffer.concat([
|
|
153
|
+
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:create")).slice(0, 8),
|
|
154
|
+
bufferData,
|
|
155
|
+
buffer_1.Buffer.alloc(10),
|
|
156
|
+
]);
|
|
157
|
+
return new web3_js_1.TransactionInstruction({
|
|
158
|
+
keys: keys,
|
|
159
|
+
programId: programId,
|
|
160
|
+
data: bufferData,
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
exports.createStreamInstruction = createStreamInstruction;
|
|
164
|
+
var createUncheckedStreamInstruction = function (data, programId, accounts) {
|
|
165
|
+
var keys = [
|
|
166
|
+
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
167
|
+
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
168
|
+
{ pubkey: accounts.metadata, isSigner: false, isWritable: true },
|
|
169
|
+
{ pubkey: accounts.escrowTokens, isSigner: false, isWritable: true },
|
|
170
|
+
{ pubkey: accounts.withdrawor, isSigner: false, isWritable: true },
|
|
171
|
+
{ pubkey: accounts.mint, isSigner: false, isWritable: false },
|
|
172
|
+
{ pubkey: accounts.feeOracle, isSigner: false, isWritable: false },
|
|
173
|
+
{ pubkey: accounts.rent, isSigner: false, isWritable: false },
|
|
174
|
+
{ pubkey: accounts.timelockProgram, isSigner: false, isWritable: false },
|
|
175
|
+
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
176
|
+
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
|
|
177
|
+
];
|
|
178
|
+
if (accounts.payer) {
|
|
179
|
+
keys.unshift({
|
|
180
|
+
pubkey: accounts.payer,
|
|
181
|
+
isSigner: true,
|
|
182
|
+
isWritable: true,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
var bufferData = buffer_1.Buffer.alloc(Layout.createUncheckedStreamLayout.span);
|
|
186
|
+
var encodedUIntArray = new TextEncoder().encode(data.name);
|
|
187
|
+
var streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
188
|
+
var decodedData = {
|
|
189
|
+
start_time: data.start.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
190
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
191
|
+
period: data.period.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
192
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
193
|
+
cliff: data.cliff.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
194
|
+
cliff_amount: data.cliffAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
195
|
+
cancelable_by_sender: Number(data.cancelableBySender),
|
|
196
|
+
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
197
|
+
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
198
|
+
transferable_by_sender: Number(data.transferableBySender),
|
|
199
|
+
transferable_by_recipient: Number(data.transferableByRecipient),
|
|
200
|
+
can_topup: Number(data.canTopup),
|
|
201
|
+
stream_name: streamNameBuffer,
|
|
202
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
203
|
+
recipient: data.recipient.toBuffer(),
|
|
204
|
+
partner: data.partner.toBuffer(),
|
|
205
|
+
pausable: 1,
|
|
206
|
+
can_update_rate: 1,
|
|
207
|
+
};
|
|
208
|
+
var encodeLength = Layout.createUncheckedStreamLayout.encode(decodedData, bufferData);
|
|
209
|
+
bufferData = bufferData.slice(0, encodeLength);
|
|
210
|
+
var digest = accounts.payer
|
|
211
|
+
? js_sha256_1.sha256.digest("global:create_unchecked_with_payer")
|
|
212
|
+
: js_sha256_1.sha256.digest("global:create_unchecked");
|
|
213
|
+
bufferData = buffer_1.Buffer.concat([buffer_1.Buffer.from(digest).slice(0, 8), bufferData, buffer_1.Buffer.alloc(10)]);
|
|
214
|
+
return new web3_js_1.TransactionInstruction({
|
|
215
|
+
keys: keys,
|
|
216
|
+
programId: programId,
|
|
217
|
+
data: bufferData,
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
|
|
221
|
+
var withdrawStreamInstruction = function (amount, programId, _a) {
|
|
222
|
+
var authority = _a.authority, recipient = _a.recipient, recipientTokens = _a.recipientTokens, metadata = _a.metadata, escrowTokens = _a.escrowTokens, streamflowTreasury = _a.streamflowTreasury, streamflowTreasuryTokens = _a.streamflowTreasuryTokens, partner = _a.partner, partnerTokens = _a.partnerTokens, mint = _a.mint, tokenProgram = _a.tokenProgram;
|
|
223
|
+
var keys = [
|
|
224
|
+
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
225
|
+
{ pubkey: recipient, isSigner: false, isWritable: true },
|
|
226
|
+
{ pubkey: recipientTokens, isSigner: false, isWritable: true },
|
|
227
|
+
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
228
|
+
{ pubkey: escrowTokens, isSigner: false, isWritable: true },
|
|
229
|
+
{
|
|
230
|
+
pubkey: streamflowTreasury,
|
|
231
|
+
isSigner: false,
|
|
232
|
+
isWritable: true,
|
|
233
|
+
},
|
|
234
|
+
{ pubkey: streamflowTreasuryTokens, isSigner: false, isWritable: true },
|
|
235
|
+
{ pubkey: partner, isSigner: false, isWritable: true },
|
|
236
|
+
{ pubkey: partnerTokens, isSigner: false, isWritable: true },
|
|
237
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
238
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
239
|
+
];
|
|
240
|
+
var data = buffer_1.Buffer.alloc(Layout.withdrawStreamLayout.span);
|
|
241
|
+
var decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
|
|
242
|
+
var encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
|
|
243
|
+
data = data.slice(0, encodeLength);
|
|
244
|
+
data = buffer_1.Buffer.concat([
|
|
245
|
+
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:withdraw")).slice(0, 8),
|
|
246
|
+
data,
|
|
247
|
+
buffer_1.Buffer.alloc(10),
|
|
248
|
+
]);
|
|
249
|
+
return new web3_js_1.TransactionInstruction({
|
|
250
|
+
keys: keys,
|
|
251
|
+
programId: programId,
|
|
252
|
+
data: data,
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
exports.withdrawStreamInstruction = withdrawStreamInstruction;
|
|
256
|
+
var cancelStreamInstruction = function (programId, _a) {
|
|
257
|
+
var authority = _a.authority, sender = _a.sender, senderTokens = _a.senderTokens, recipient = _a.recipient, recipientTokens = _a.recipientTokens, metadata = _a.metadata, escrowTokens = _a.escrowTokens, streamflowTreasury = _a.streamflowTreasury, streamflowTreasuryTokens = _a.streamflowTreasuryTokens, partner = _a.partner, partnerTokens = _a.partnerTokens, mint = _a.mint, tokenProgram = _a.tokenProgram;
|
|
258
|
+
var keys = [
|
|
259
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
260
|
+
{ pubkey: sender, isSigner: false, isWritable: true },
|
|
261
|
+
{ pubkey: senderTokens, isSigner: false, isWritable: true },
|
|
262
|
+
{ pubkey: recipient, isSigner: false, isWritable: true },
|
|
263
|
+
{ pubkey: recipientTokens, isSigner: false, isWritable: true },
|
|
264
|
+
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
265
|
+
{ pubkey: escrowTokens, isSigner: false, isWritable: true },
|
|
266
|
+
{
|
|
267
|
+
pubkey: streamflowTreasury,
|
|
268
|
+
isSigner: false,
|
|
269
|
+
isWritable: true,
|
|
270
|
+
},
|
|
271
|
+
{ pubkey: streamflowTreasuryTokens, isSigner: false, isWritable: true },
|
|
272
|
+
{ pubkey: partner, isSigner: false, isWritable: true },
|
|
273
|
+
{ pubkey: partnerTokens, isSigner: false, isWritable: true },
|
|
274
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
275
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
276
|
+
];
|
|
277
|
+
var data = buffer_1.Buffer.concat([
|
|
278
|
+
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:cancel")).slice(0, 8),
|
|
279
|
+
buffer_1.Buffer.alloc(10),
|
|
280
|
+
]);
|
|
281
|
+
return new web3_js_1.TransactionInstruction({
|
|
282
|
+
keys: keys,
|
|
283
|
+
programId: programId,
|
|
284
|
+
data: data,
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
exports.cancelStreamInstruction = cancelStreamInstruction;
|
|
288
|
+
var transferStreamInstruction = function (programId, _a) {
|
|
289
|
+
var authority = _a.authority, newRecipient = _a.newRecipient, newRecipientTokens = _a.newRecipientTokens, metadata = _a.metadata, mint = _a.mint, rent = _a.rent, tokenProgram = _a.tokenProgram, associatedTokenProgram = _a.associatedTokenProgram, systemProgram = _a.systemProgram;
|
|
290
|
+
var keys = [
|
|
291
|
+
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
292
|
+
{ pubkey: newRecipient, isSigner: false, isWritable: true },
|
|
293
|
+
{ pubkey: newRecipientTokens, isSigner: false, isWritable: true },
|
|
294
|
+
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
295
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
296
|
+
{ pubkey: rent, isSigner: false, isWritable: false },
|
|
297
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
298
|
+
{ pubkey: associatedTokenProgram, isSigner: false, isWritable: false },
|
|
299
|
+
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
300
|
+
];
|
|
301
|
+
var data = buffer_1.Buffer.concat([
|
|
302
|
+
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:transfer_recipient")).slice(0, 8),
|
|
303
|
+
buffer_1.Buffer.alloc(10),
|
|
304
|
+
]);
|
|
305
|
+
return new web3_js_1.TransactionInstruction({
|
|
306
|
+
keys: keys,
|
|
307
|
+
programId: programId,
|
|
308
|
+
data: data,
|
|
309
|
+
});
|
|
310
|
+
};
|
|
311
|
+
exports.transferStreamInstruction = transferStreamInstruction;
|
|
312
|
+
var topupStreamInstruction = function (amount, programId, _a) {
|
|
313
|
+
var sender = _a.sender, senderTokens = _a.senderTokens, metadata = _a.metadata, escrowTokens = _a.escrowTokens, streamflowTreasury = _a.streamflowTreasury, streamflowTreasuryTokens = _a.streamflowTreasuryTokens, partner = _a.partner, partnerTokens = _a.partnerTokens, mint = _a.mint, tokenProgram = _a.tokenProgram, withdrawor = _a.withdrawor, systemProgram = _a.systemProgram;
|
|
314
|
+
var keys = [
|
|
315
|
+
{ pubkey: sender, isSigner: true, isWritable: true },
|
|
316
|
+
{ pubkey: senderTokens, isSigner: false, isWritable: true },
|
|
317
|
+
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
318
|
+
{ pubkey: escrowTokens, isSigner: false, isWritable: true },
|
|
319
|
+
{
|
|
320
|
+
pubkey: streamflowTreasury,
|
|
321
|
+
isSigner: false,
|
|
322
|
+
isWritable: true,
|
|
323
|
+
},
|
|
324
|
+
{ pubkey: streamflowTreasuryTokens, isSigner: false, isWritable: true },
|
|
325
|
+
{ pubkey: withdrawor, isSigner: false, isWritable: true },
|
|
326
|
+
{ pubkey: partner, isSigner: false, isWritable: true },
|
|
327
|
+
{ pubkey: partnerTokens, isSigner: false, isWritable: true },
|
|
328
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
329
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
330
|
+
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
331
|
+
];
|
|
332
|
+
var data = buffer_1.Buffer.alloc(Layout.topupStreamLayout.span);
|
|
333
|
+
var decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
|
|
334
|
+
var encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
|
|
335
|
+
data = data.slice(0, encodeLength);
|
|
336
|
+
data = buffer_1.Buffer.concat([
|
|
337
|
+
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:topup")).slice(0, 8),
|
|
338
|
+
data,
|
|
339
|
+
buffer_1.Buffer.alloc(10),
|
|
340
|
+
]);
|
|
341
|
+
return new web3_js_1.TransactionInstruction({
|
|
342
|
+
keys: keys,
|
|
343
|
+
programId: programId,
|
|
344
|
+
data: data,
|
|
345
|
+
});
|
|
346
|
+
};
|
|
347
|
+
exports.topupStreamInstruction = topupStreamInstruction;
|
|
348
|
+
var prepareWrappedAccount = function (connection, senderAddress, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
349
|
+
var tokenAccount, accInfo, instructions;
|
|
350
|
+
var _a, _b;
|
|
351
|
+
return __generator(this, function (_c) {
|
|
352
|
+
switch (_c.label) {
|
|
353
|
+
case 0: return [4 /*yield*/, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, senderAddress, true)];
|
|
354
|
+
case 1:
|
|
355
|
+
tokenAccount = _c.sent();
|
|
356
|
+
return [4 /*yield*/, connection.getParsedAccountInfo(tokenAccount)];
|
|
357
|
+
case 2:
|
|
358
|
+
accInfo = _c.sent();
|
|
359
|
+
instructions = ((_b = (_a = accInfo.value) === null || _a === void 0 ? void 0 : _a.lamports) !== null && _b !== void 0 ? _b : 0) > 0
|
|
360
|
+
? []
|
|
361
|
+
: [
|
|
362
|
+
(0, spl_token_1.createAssociatedTokenAccountInstruction)(senderAddress, tokenAccount, senderAddress, spl_token_1.NATIVE_MINT),
|
|
363
|
+
];
|
|
364
|
+
return [2 /*return*/, __spreadArray(__spreadArray([], __read(instructions), false), [
|
|
365
|
+
web3_js_1.SystemProgram.transfer({
|
|
366
|
+
fromPubkey: senderAddress,
|
|
367
|
+
toPubkey: tokenAccount,
|
|
368
|
+
lamports: amount.mul(new bn_js_1.default(constants_1.BASE_FEE)).div(new bn_js_1.default(1000000)).toNumber(),
|
|
369
|
+
}),
|
|
370
|
+
(0, spl_token_1.createSyncNativeInstruction)(tokenAccount),
|
|
371
|
+
], false)];
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
}); };
|
|
375
|
+
exports.prepareWrappedAccount = prepareWrappedAccount;
|