@streamflow/stream 3.0.0 → 3.0.1-3.1
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 +93 -91
- package/dist/Stream.js +15 -15
- package/dist/StreamClient.d.ts +50 -11
- package/dist/StreamClient.js +453 -183
- package/dist/__tests__/test_dependencies/airdrop/airdrop-request.d.ts +3 -0
- package/dist/__tests__/test_dependencies/airdrop/airdrop-request.js +67 -0
- package/dist/__tests__/test_dependencies/airdrop/airdrop.d.ts +6 -0
- package/dist/__tests__/test_dependencies/airdrop/airdrop.js +215 -0
- package/dist/__tests__/test_dependencies/constants/index.d.ts +122 -0
- package/dist/__tests__/test_dependencies/constants/index.js +158 -0
- package/dist/__tests__/test_dependencies/idl/airdrop.d.ts +27 -0
- package/dist/__tests__/test_dependencies/idl/airdrop.js +171 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +4 -1
- package/dist/{idl.d.ts → idl/timelock.d.ts} +0 -0
- package/dist/{idl.js → idl/timelock.js} +0 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -3
- package/dist/instructions.d.ts +46 -11
- package/dist/instructions.js +183 -13
- package/dist/layout.d.ts +4 -0
- package/dist/layout.js +24 -1
- package/dist/types.d.ts +125 -41
- package/dist/types.js +71 -1
- package/dist/utils.d.ts +6 -6
- package/dist/utils.js +38 -30
- package/package.json +16 -2
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = {
|
|
4
|
+
version: "0.1.0",
|
|
5
|
+
name: "airdrop",
|
|
6
|
+
instructions: [
|
|
7
|
+
{
|
|
8
|
+
name: "initializeAirdrop",
|
|
9
|
+
accounts: [
|
|
10
|
+
{
|
|
11
|
+
name: "initializer",
|
|
12
|
+
isMut: false,
|
|
13
|
+
isSigner: true,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "initializerDepositTokenAccount",
|
|
17
|
+
isMut: true,
|
|
18
|
+
isSigner: false,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "airdropAccount",
|
|
22
|
+
isMut: true,
|
|
23
|
+
isSigner: true,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "airdropTokenAccount",
|
|
27
|
+
isMut: true,
|
|
28
|
+
isSigner: false,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "systemProgram",
|
|
32
|
+
isMut: false,
|
|
33
|
+
isSigner: false,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "tokenProgram",
|
|
37
|
+
isMut: false,
|
|
38
|
+
isSigner: false,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
args: [
|
|
42
|
+
{
|
|
43
|
+
name: "airdropAmount",
|
|
44
|
+
type: "u64",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "withdrawAmount",
|
|
48
|
+
type: "u64",
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "getAirdrop",
|
|
54
|
+
accounts: [
|
|
55
|
+
{
|
|
56
|
+
name: "taker",
|
|
57
|
+
isMut: false,
|
|
58
|
+
isSigner: true,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "takerReceiveTokenAccount",
|
|
62
|
+
isMut: true,
|
|
63
|
+
isSigner: false,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "airdropAccount",
|
|
67
|
+
isMut: true,
|
|
68
|
+
isSigner: false,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "mint",
|
|
72
|
+
isMut: false,
|
|
73
|
+
isSigner: false,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "airdropTokenAccount",
|
|
77
|
+
isMut: true,
|
|
78
|
+
isSigner: false,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "pdaAccount",
|
|
82
|
+
isMut: false,
|
|
83
|
+
isSigner: false,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "tokenProgram",
|
|
87
|
+
isMut: false,
|
|
88
|
+
isSigner: false,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "associatedTokenProgram",
|
|
92
|
+
isMut: false,
|
|
93
|
+
isSigner: false,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: "systemProgram",
|
|
97
|
+
isMut: false,
|
|
98
|
+
isSigner: false,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "rent",
|
|
102
|
+
isMut: false,
|
|
103
|
+
isSigner: false,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
args: [],
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "cancelAirdrop",
|
|
110
|
+
accounts: [
|
|
111
|
+
{
|
|
112
|
+
name: "initializer",
|
|
113
|
+
isMut: true,
|
|
114
|
+
isSigner: true,
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: "initializerDepositTokenAccount",
|
|
118
|
+
isMut: true,
|
|
119
|
+
isSigner: false,
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: "pdaAccount",
|
|
123
|
+
isMut: false,
|
|
124
|
+
isSigner: false,
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: "airdropAccount",
|
|
128
|
+
isMut: true,
|
|
129
|
+
isSigner: false,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: "airdropTokenAccount",
|
|
133
|
+
isMut: true,
|
|
134
|
+
isSigner: false,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: "tokenProgram",
|
|
138
|
+
isMut: false,
|
|
139
|
+
isSigner: false,
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
args: [],
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
accounts: [
|
|
146
|
+
{
|
|
147
|
+
name: "AirdropAccount",
|
|
148
|
+
type: {
|
|
149
|
+
kind: "struct",
|
|
150
|
+
fields: [
|
|
151
|
+
{
|
|
152
|
+
name: "initializerKey",
|
|
153
|
+
type: "publicKey",
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: "initializerDepositTokenAccount",
|
|
157
|
+
type: "publicKey",
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
name: "airdropTokenAccount",
|
|
161
|
+
type: "publicKey",
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: "withdrawAmount",
|
|
165
|
+
type: "u64",
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
};
|
package/dist/constants.d.ts
CHANGED
|
@@ -13,3 +13,6 @@ export declare const STREAMFLOW_DEVNET_PROGRAM_ID = "FGjLaVo5zLGdzCxMo9gu9tXr1kz
|
|
|
13
13
|
export declare const STREAMFLOW_TREASURY_PUBLIC_KEY: PublicKey;
|
|
14
14
|
export declare const WITHDRAWOR_PUBLIC_KEY: PublicKey;
|
|
15
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;
|
package/dist/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
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;
|
|
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
5
|
var web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
var types_1 = require("./types");
|
|
7
7
|
exports.TX_FINALITY_CONFIRMED = "confirmed";
|
|
@@ -18,3 +18,6 @@ exports.STREAMFLOW_DEVNET_PROGRAM_ID = "FGjLaVo5zLGdzCxMo9gu9tXr1kzTToKd8C8K7YS5
|
|
|
18
18
|
exports.STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js_1.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
|
|
19
19
|
exports.WITHDRAWOR_PUBLIC_KEY = new web3_js_1.PublicKey("wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u");
|
|
20
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
|
|
File without changes
|
|
File without changes
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -21,5 +25,5 @@ Object.defineProperty(exports, "StreamClient", { enumerable: true, get: function
|
|
|
21
25
|
__exportStar(require("./utils"), exports);
|
|
22
26
|
__exportStar(require("./types"), exports);
|
|
23
27
|
__exportStar(require("./instructions"), exports);
|
|
24
|
-
var
|
|
25
|
-
Object.defineProperty(exports, "BN", { enumerable: true, get: function () { return
|
|
28
|
+
var bn_js_1 = require("bn.js");
|
|
29
|
+
Object.defineProperty(exports, "BN", { enumerable: true, get: function () { return __importDefault(bn_js_1).default; } });
|
package/dist/instructions.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
-
import
|
|
1
|
+
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import BN from "bn.js";
|
|
3
3
|
interface CreateStreamData {
|
|
4
|
-
start:
|
|
5
|
-
depositedAmount:
|
|
6
|
-
period:
|
|
7
|
-
amountPerPeriod:
|
|
8
|
-
cliff:
|
|
9
|
-
cliffAmount:
|
|
4
|
+
start: BN;
|
|
5
|
+
depositedAmount: BN;
|
|
6
|
+
period: BN;
|
|
7
|
+
amountPerPeriod: BN;
|
|
8
|
+
cliff: BN;
|
|
9
|
+
cliffAmount: BN;
|
|
10
10
|
cancelableBySender: boolean;
|
|
11
11
|
cancelableByRecipient: boolean;
|
|
12
12
|
automaticWithdrawal: boolean;
|
|
@@ -14,7 +14,7 @@ interface CreateStreamData {
|
|
|
14
14
|
transferableByRecipient: boolean;
|
|
15
15
|
canTopup: boolean;
|
|
16
16
|
name: string;
|
|
17
|
-
withdrawFrequency:
|
|
17
|
+
withdrawFrequency: BN;
|
|
18
18
|
}
|
|
19
19
|
interface CreateStreamAccounts {
|
|
20
20
|
sender: PublicKey;
|
|
@@ -37,6 +37,38 @@ interface CreateStreamAccounts {
|
|
|
37
37
|
systemProgram: PublicKey;
|
|
38
38
|
}
|
|
39
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
|
+
sender: PublicKey;
|
|
60
|
+
senderTokens: PublicKey;
|
|
61
|
+
metadata: PublicKey;
|
|
62
|
+
escrowTokens: PublicKey;
|
|
63
|
+
mint: PublicKey;
|
|
64
|
+
feeOracle: PublicKey;
|
|
65
|
+
rent: PublicKey;
|
|
66
|
+
timelockProgram: PublicKey;
|
|
67
|
+
tokenProgram: PublicKey;
|
|
68
|
+
withdrawor: PublicKey;
|
|
69
|
+
systemProgram: PublicKey;
|
|
70
|
+
}
|
|
71
|
+
export declare const createUncheckedStreamInstruction: (data: CreateUncheckedStreamData, programId: PublicKey, accounts: CreateUncheckedStreamAccounts) => TransactionInstruction;
|
|
40
72
|
interface WithdrawAccounts {
|
|
41
73
|
authority: PublicKey;
|
|
42
74
|
recipient: PublicKey;
|
|
@@ -50,7 +82,7 @@ interface WithdrawAccounts {
|
|
|
50
82
|
mint: PublicKey;
|
|
51
83
|
tokenProgram: PublicKey;
|
|
52
84
|
}
|
|
53
|
-
export declare const withdrawStreamInstruction: (amount:
|
|
85
|
+
export declare const withdrawStreamInstruction: (amount: BN, programId: PublicKey, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }: WithdrawAccounts) => TransactionInstruction;
|
|
54
86
|
interface CancelAccounts {
|
|
55
87
|
authority: PublicKey;
|
|
56
88
|
sender: PublicKey;
|
|
@@ -93,5 +125,8 @@ interface TopupAccounts {
|
|
|
93
125
|
withdrawor: PublicKey;
|
|
94
126
|
systemProgram: PublicKey;
|
|
95
127
|
}
|
|
96
|
-
export declare const topupStreamInstruction: (amount:
|
|
128
|
+
export declare const topupStreamInstruction: (amount: BN, programId: PublicKey, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }: TopupAccounts) => TransactionInstruction;
|
|
129
|
+
export declare const syncNativeInstructionData: import("@solana/buffer-layout").Structure<any>;
|
|
130
|
+
export declare const createSyncNativeInstruction: (account: PublicKey) => TransactionInstruction;
|
|
131
|
+
export declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount: BN) => Promise<TransactionInstruction[]>;
|
|
97
132
|
export {};
|
package/dist/instructions.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -18,12 +22,80 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
18
22
|
__setModuleDefault(result, mod);
|
|
19
23
|
return result;
|
|
20
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
|
+
};
|
|
21
89
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.withdrawStreamInstruction = exports.createStreamInstruction = void 0;
|
|
90
|
+
exports.prepareWrappedAccount = exports.createSyncNativeInstruction = exports.syncNativeInstructionData = exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
|
|
23
91
|
var buffer_1 = require("buffer");
|
|
24
92
|
var web3_js_1 = require("@solana/web3.js");
|
|
93
|
+
var bn_js_1 = __importDefault(require("bn.js"));
|
|
25
94
|
var js_sha256_1 = require("js-sha256");
|
|
95
|
+
var buffer_layout_1 = require("@solana/buffer-layout");
|
|
26
96
|
var Layout = __importStar(require("./layout"));
|
|
97
|
+
var spl_token_1 = require("@solana/spl-token");
|
|
98
|
+
var constants_1 = require("./constants");
|
|
27
99
|
var createStreamInstruction = function (data, programId, accounts) {
|
|
28
100
|
var keys = [
|
|
29
101
|
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
@@ -61,12 +133,12 @@ var createStreamInstruction = function (data, programId, accounts) {
|
|
|
61
133
|
var encodedUIntArray = new TextEncoder().encode(data.name);
|
|
62
134
|
var streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
63
135
|
var decodedData = {
|
|
64
|
-
start_time: data.start.
|
|
65
|
-
net_amount_deposited: data.depositedAmount.
|
|
66
|
-
period: data.period.
|
|
67
|
-
amount_per_period: data.amountPerPeriod.
|
|
68
|
-
cliff: data.cliff.
|
|
69
|
-
cliff_amount: data.cliffAmount.
|
|
136
|
+
start_time: data.start.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
137
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
138
|
+
period: data.period.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
139
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
140
|
+
cliff: data.cliff.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
141
|
+
cliff_amount: data.cliffAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
70
142
|
cancelable_by_sender: data.cancelableBySender,
|
|
71
143
|
cancelable_by_recipient: data.cancelableByRecipient,
|
|
72
144
|
automatic_withdrawal: data.automaticWithdrawal,
|
|
@@ -74,13 +146,14 @@ var createStreamInstruction = function (data, programId, accounts) {
|
|
|
74
146
|
transferable_by_recipient: data.transferableByRecipient,
|
|
75
147
|
can_topup: data.canTopup,
|
|
76
148
|
stream_name: streamNameBuffer,
|
|
77
|
-
withdraw_frequency: data.withdrawFrequency.
|
|
149
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
78
150
|
};
|
|
79
151
|
var encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
|
|
80
152
|
bufferData = bufferData.slice(0, encodeLength);
|
|
81
153
|
bufferData = buffer_1.Buffer.concat([
|
|
82
154
|
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:create")).slice(0, 8),
|
|
83
155
|
bufferData,
|
|
156
|
+
buffer_1.Buffer.alloc(10)
|
|
84
157
|
]);
|
|
85
158
|
return new web3_js_1.TransactionInstruction({
|
|
86
159
|
keys: keys,
|
|
@@ -89,6 +162,57 @@ var createStreamInstruction = function (data, programId, accounts) {
|
|
|
89
162
|
});
|
|
90
163
|
};
|
|
91
164
|
exports.createStreamInstruction = createStreamInstruction;
|
|
165
|
+
var createUncheckedStreamInstruction = function (data, programId, accounts) {
|
|
166
|
+
var keys = [
|
|
167
|
+
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
168
|
+
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
169
|
+
{ pubkey: accounts.metadata, isSigner: false, isWritable: true },
|
|
170
|
+
{ pubkey: accounts.escrowTokens, isSigner: false, isWritable: true },
|
|
171
|
+
{ pubkey: accounts.withdrawor, isSigner: false, isWritable: true },
|
|
172
|
+
{ pubkey: accounts.mint, isSigner: false, isWritable: false },
|
|
173
|
+
{ pubkey: accounts.feeOracle, isSigner: false, isWritable: false },
|
|
174
|
+
{ pubkey: accounts.rent, isSigner: false, isWritable: false },
|
|
175
|
+
{ pubkey: accounts.timelockProgram, isSigner: false, isWritable: false },
|
|
176
|
+
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
177
|
+
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
|
|
178
|
+
];
|
|
179
|
+
var bufferData = buffer_1.Buffer.alloc(Layout.createUncheckedStreamLayout.span);
|
|
180
|
+
var encodedUIntArray = new TextEncoder().encode(data.name);
|
|
181
|
+
var streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
182
|
+
var decodedData = {
|
|
183
|
+
start_time: data.start.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
184
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
185
|
+
period: data.period.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
186
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
187
|
+
cliff: data.cliff.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
188
|
+
cliff_amount: data.cliffAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
189
|
+
cancelable_by_sender: data.cancelableBySender,
|
|
190
|
+
cancelable_by_recipient: data.cancelableByRecipient,
|
|
191
|
+
automatic_withdrawal: data.automaticWithdrawal,
|
|
192
|
+
transferable_by_sender: data.transferableBySender,
|
|
193
|
+
transferable_by_recipient: data.transferableByRecipient,
|
|
194
|
+
can_topup: data.canTopup,
|
|
195
|
+
stream_name: streamNameBuffer,
|
|
196
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
197
|
+
recipient: data.recipient.toBuffer(),
|
|
198
|
+
partner: data.partner.toBuffer(),
|
|
199
|
+
pausable: buffer_1.Buffer.alloc(1),
|
|
200
|
+
can_update_rate: buffer_1.Buffer.alloc(1),
|
|
201
|
+
};
|
|
202
|
+
var encodeLength = Layout.createUncheckedStreamLayout.encode(decodedData, bufferData);
|
|
203
|
+
bufferData = bufferData.slice(0, encodeLength);
|
|
204
|
+
bufferData = buffer_1.Buffer.concat([
|
|
205
|
+
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:create_unchecked")).slice(0, 8),
|
|
206
|
+
bufferData,
|
|
207
|
+
buffer_1.Buffer.alloc(10),
|
|
208
|
+
]);
|
|
209
|
+
return new web3_js_1.TransactionInstruction({
|
|
210
|
+
keys: keys,
|
|
211
|
+
programId: programId,
|
|
212
|
+
data: bufferData,
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
|
|
92
216
|
var withdrawStreamInstruction = function (amount, programId, _a) {
|
|
93
217
|
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;
|
|
94
218
|
var keys = [
|
|
@@ -109,12 +233,13 @@ var withdrawStreamInstruction = function (amount, programId, _a) {
|
|
|
109
233
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
110
234
|
];
|
|
111
235
|
var data = buffer_1.Buffer.alloc(Layout.withdrawStreamLayout.span);
|
|
112
|
-
var decodedData = { amount: amount.
|
|
236
|
+
var decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
|
|
113
237
|
var encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
|
|
114
238
|
data = data.slice(0, encodeLength);
|
|
115
239
|
data = buffer_1.Buffer.concat([
|
|
116
240
|
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:withdraw")).slice(0, 8),
|
|
117
241
|
data,
|
|
242
|
+
buffer_1.Buffer.alloc(10)
|
|
118
243
|
]);
|
|
119
244
|
return new web3_js_1.TransactionInstruction({
|
|
120
245
|
keys: keys,
|
|
@@ -144,7 +269,10 @@ var cancelStreamInstruction = function (programId, _a) {
|
|
|
144
269
|
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
145
270
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
146
271
|
];
|
|
147
|
-
var data = buffer_1.Buffer.
|
|
272
|
+
var data = buffer_1.Buffer.concat([
|
|
273
|
+
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:cancel")).slice(0, 8),
|
|
274
|
+
buffer_1.Buffer.alloc(10),
|
|
275
|
+
]);
|
|
148
276
|
return new web3_js_1.TransactionInstruction({
|
|
149
277
|
keys: keys,
|
|
150
278
|
programId: programId,
|
|
@@ -165,7 +293,10 @@ var transferStreamInstruction = function (programId, _a) {
|
|
|
165
293
|
{ pubkey: associatedTokenProgram, isSigner: false, isWritable: false },
|
|
166
294
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
167
295
|
];
|
|
168
|
-
var data = buffer_1.Buffer.
|
|
296
|
+
var data = buffer_1.Buffer.concat([
|
|
297
|
+
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:transfer_recipient")).slice(0, 8),
|
|
298
|
+
buffer_1.Buffer.alloc(10),
|
|
299
|
+
]);
|
|
169
300
|
return new web3_js_1.TransactionInstruction({
|
|
170
301
|
keys: keys,
|
|
171
302
|
programId: programId,
|
|
@@ -194,12 +325,13 @@ var topupStreamInstruction = function (amount, programId, _a) {
|
|
|
194
325
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
195
326
|
];
|
|
196
327
|
var data = buffer_1.Buffer.alloc(Layout.topupStreamLayout.span);
|
|
197
|
-
var decodedData = { amount: amount.
|
|
328
|
+
var decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
|
|
198
329
|
var encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
|
|
199
330
|
data = data.slice(0, encodeLength);
|
|
200
331
|
data = buffer_1.Buffer.concat([
|
|
201
332
|
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:topup")).slice(0, 8),
|
|
202
333
|
data,
|
|
334
|
+
buffer_1.Buffer.alloc(10)
|
|
203
335
|
]);
|
|
204
336
|
return new web3_js_1.TransactionInstruction({
|
|
205
337
|
keys: keys,
|
|
@@ -208,3 +340,41 @@ var topupStreamInstruction = function (amount, programId, _a) {
|
|
|
208
340
|
});
|
|
209
341
|
};
|
|
210
342
|
exports.topupStreamInstruction = topupStreamInstruction;
|
|
343
|
+
// TODO: Use native createSyncNativeInstruction after migrating to newer @solana/spl-token
|
|
344
|
+
var SyncNativeIndex = 17;
|
|
345
|
+
exports.syncNativeInstructionData = (0, buffer_layout_1.struct)([(0, buffer_layout_1.u8)('instruction')]);
|
|
346
|
+
var createSyncNativeInstruction = function (account) {
|
|
347
|
+
var keys = [{ pubkey: account, isSigner: false, isWritable: true }];
|
|
348
|
+
var data = buffer_1.Buffer.alloc(exports.syncNativeInstructionData.span);
|
|
349
|
+
exports.syncNativeInstructionData.encode({ instruction: SyncNativeIndex }, data);
|
|
350
|
+
return new web3_js_1.TransactionInstruction({ keys: keys, programId: spl_token_1.TOKEN_PROGRAM_ID, data: data });
|
|
351
|
+
};
|
|
352
|
+
exports.createSyncNativeInstruction = createSyncNativeInstruction;
|
|
353
|
+
var prepareWrappedAccount = function (connection, senderAddress, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
354
|
+
var tokenAccount, accInfo, instructions;
|
|
355
|
+
var _a, _b;
|
|
356
|
+
return __generator(this, function (_c) {
|
|
357
|
+
switch (_c.label) {
|
|
358
|
+
case 0: return [4 /*yield*/, spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.NATIVE_MINT, senderAddress, true)];
|
|
359
|
+
case 1:
|
|
360
|
+
tokenAccount = _c.sent();
|
|
361
|
+
return [4 /*yield*/, connection.getParsedAccountInfo(tokenAccount)];
|
|
362
|
+
case 2:
|
|
363
|
+
accInfo = _c.sent();
|
|
364
|
+
instructions = ((_b = (_a = accInfo.value) === null || _a === void 0 ? void 0 : _a.lamports) !== null && _b !== void 0 ? _b : 0) > 0
|
|
365
|
+
? []
|
|
366
|
+
: [
|
|
367
|
+
spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.NATIVE_MINT, tokenAccount, senderAddress, senderAddress),
|
|
368
|
+
];
|
|
369
|
+
return [2 /*return*/, __spreadArray(__spreadArray([], __read(instructions), false), [
|
|
370
|
+
web3_js_1.SystemProgram.transfer({
|
|
371
|
+
fromPubkey: senderAddress,
|
|
372
|
+
toPubkey: tokenAccount,
|
|
373
|
+
lamports: amount.mul(new bn_js_1.default(constants_1.BASE_FEE)).div(new bn_js_1.default(1000000)).toNumber(),
|
|
374
|
+
}),
|
|
375
|
+
(0, exports.createSyncNativeInstruction)(tokenAccount),
|
|
376
|
+
], false)];
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}); };
|
|
380
|
+
exports.prepareWrappedAccount = prepareWrappedAccount;
|
package/dist/layout.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ export declare const streamLayout: typeof BufferLayout.Structure;
|
|
|
7
7
|
* Create stream instruction layout
|
|
8
8
|
*/
|
|
9
9
|
export declare const createStreamLayout: typeof BufferLayout.Structure;
|
|
10
|
+
/**
|
|
11
|
+
* Create unchecked stream instruction layout
|
|
12
|
+
*/
|
|
13
|
+
export declare const createUncheckedStreamLayout: typeof BufferLayout.Structure;
|
|
10
14
|
/**
|
|
11
15
|
* Withdraw stream instruction layout
|
|
12
16
|
*/
|
package/dist/layout.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.topupStreamLayout = exports.withdrawStreamLayout = exports.createStreamLayout = exports.streamLayout = void 0;
|
|
3
|
+
exports.topupStreamLayout = exports.withdrawStreamLayout = exports.createUncheckedStreamLayout = exports.createStreamLayout = exports.streamLayout = void 0;
|
|
4
4
|
var BufferLayout = require("buffer-layout");
|
|
5
5
|
/**
|
|
6
6
|
* Stream layout
|
|
@@ -63,6 +63,29 @@ exports.createStreamLayout = BufferLayout.struct([
|
|
|
63
63
|
BufferLayout.blob(64, "stream_name"),
|
|
64
64
|
BufferLayout.blob(8, "withdraw_frequency"),
|
|
65
65
|
]);
|
|
66
|
+
/**
|
|
67
|
+
* Create unchecked stream instruction layout
|
|
68
|
+
*/
|
|
69
|
+
exports.createUncheckedStreamLayout = BufferLayout.struct([
|
|
70
|
+
BufferLayout.blob(8, "start_time"),
|
|
71
|
+
BufferLayout.blob(8, "net_amount_deposited"),
|
|
72
|
+
BufferLayout.blob(8, "period"),
|
|
73
|
+
BufferLayout.blob(8, "amount_per_period"),
|
|
74
|
+
BufferLayout.blob(8, "cliff"),
|
|
75
|
+
BufferLayout.blob(8, "cliff_amount"),
|
|
76
|
+
BufferLayout.u8("cancelable_by_sender"),
|
|
77
|
+
BufferLayout.u8("cancelable_by_recipient"),
|
|
78
|
+
BufferLayout.u8("automatic_withdrawal"),
|
|
79
|
+
BufferLayout.u8("transferable_by_sender"),
|
|
80
|
+
BufferLayout.u8("transferable_by_recipient"),
|
|
81
|
+
BufferLayout.u8("can_topup"),
|
|
82
|
+
BufferLayout.blob(64, "stream_name"),
|
|
83
|
+
BufferLayout.blob(8, "withdraw_frequency"),
|
|
84
|
+
BufferLayout.blob(32, "recipient"),
|
|
85
|
+
BufferLayout.blob(32, "partner"),
|
|
86
|
+
BufferLayout.u8("pausable"),
|
|
87
|
+
BufferLayout.u8("can_update_rate"),
|
|
88
|
+
]);
|
|
66
89
|
/**
|
|
67
90
|
* Withdraw stream instruction layout
|
|
68
91
|
*/
|