@streamflow/stream 6.5.0 → 7.0.0-alpha.10
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 +17 -22
- package/dist/cjs/__tests__/aptos/streamClient.spec.js +111 -0
- package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +45 -0
- package/dist/cjs/aptos/StreamClient.js +226 -0
- package/dist/cjs/aptos/constants.js +27 -0
- package/dist/{aptos → cjs/aptos}/index.js +6 -6
- package/dist/cjs/aptos/types.js +69 -0
- package/dist/{aptos → cjs/aptos}/utils.js +4 -4
- package/dist/cjs/aptos/wallet.js +34 -0
- package/dist/cjs/common/BaseStreamClient.js +23 -0
- package/dist/cjs/common/GenericStreamClient.js +102 -0
- package/dist/{common → cjs/common}/constants.js +2 -2
- package/dist/{common → cjs/common}/contractUtils.js +19 -20
- package/dist/cjs/common/utils.js +66 -0
- package/dist/cjs/evm/StreamClient.js +238 -0
- package/dist/cjs/evm/constants.js +38 -0
- package/dist/{evm → cjs/evm}/index.js +8 -8
- package/dist/{evm → cjs/evm}/types.js +26 -35
- package/dist/{evm → cjs/evm}/utils.js +2 -2
- package/dist/{index.js → cjs/index.js} +10 -10
- package/dist/cjs/solana/StreamClient.js +737 -0
- package/dist/{solana → cjs/solana}/constants.js +33 -33
- package/dist/cjs/solana/index.js +39 -0
- package/dist/{solana → cjs/solana}/instructions.js +83 -83
- package/dist/{solana → cjs/solana}/layout.js +8 -9
- package/dist/{solana → cjs/solana}/types.js +16 -26
- package/dist/cjs/solana/utils.js +134 -0
- package/dist/cjs/sui/StreamClient.js +402 -0
- package/dist/cjs/sui/constants.js +42 -0
- package/dist/{sui → cjs/sui}/index.js +5 -5
- package/dist/cjs/sui/types.js +68 -0
- package/dist/{sui → cjs/sui}/utils.js +7 -7
- package/dist/cjs/sui/wallet.js +40 -0
- package/dist/esm/__tests__/aptos/streamClient.spec.js +106 -0
- package/dist/esm/__tests__/common/GenericStreamClient.spec.js +40 -0
- package/dist/{aptos → esm/aptos}/StreamClient.d.ts +3 -3
- package/dist/esm/aptos/StreamClient.js +226 -0
- package/dist/{aptos → esm/aptos}/constants.d.ts +1 -1
- package/dist/esm/aptos/constants.js +24 -0
- package/dist/esm/aptos/index.d.ts +4 -0
- package/dist/esm/aptos/index.js +4 -0
- package/dist/{aptos → esm/aptos}/types.d.ts +13 -13
- package/dist/esm/aptos/types.js +105 -0
- package/dist/esm/aptos/utils.js +30 -0
- package/dist/esm/aptos/wallet.js +33 -0
- package/dist/{common → esm/common}/BaseStreamClient.d.ts +1 -1
- package/dist/esm/common/BaseStreamClient.js +19 -0
- package/dist/{common → esm/common}/GenericStreamClient.d.ts +6 -6
- package/dist/esm/common/GenericStreamClient.js +101 -0
- package/dist/esm/common/constants.d.ts +3 -0
- package/dist/esm/common/constants.js +3 -0
- package/dist/{common → esm/common}/contractUtils.d.ts +15 -15
- package/dist/esm/common/contractUtils.js +42 -0
- package/dist/{common → esm/common}/types.d.ts +19 -19
- package/dist/esm/common/types.js +106 -0
- package/dist/{common → esm/common}/utils.d.ts +11 -12
- package/dist/esm/common/utils.js +56 -0
- package/dist/{evm → esm/evm}/StreamClient.d.ts +4 -4
- package/dist/esm/evm/StreamClient.js +237 -0
- package/dist/esm/evm/abi.js +1255 -0
- package/dist/{evm → esm/evm}/constants.d.ts +1 -1
- package/dist/esm/evm/constants.js +35 -0
- package/dist/esm/evm/ercAbi.js +222 -0
- package/dist/esm/evm/index.d.ts +5 -0
- package/dist/esm/evm/index.js +5 -0
- package/dist/{evm → esm/evm}/types.d.ts +38 -38
- package/dist/esm/evm/types.js +102 -0
- package/dist/esm/evm/utils.js +8 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +9 -0
- package/dist/{solana → esm/solana}/StreamClient.d.ts +4 -4
- package/dist/esm/solana/StreamClient.js +711 -0
- package/dist/{solana → esm/solana}/constants.d.ts +3 -1
- package/dist/esm/solana/constants.js +62 -0
- package/dist/esm/solana/index.d.ts +6 -0
- package/dist/esm/solana/index.js +6 -0
- package/dist/esm/solana/instructionTypes.js +1 -0
- package/dist/{solana → esm/solana}/instructions.d.ts +18 -18
- package/dist/esm/solana/instructions.js +257 -0
- package/dist/{solana → esm/solana}/layout.d.ts +2 -1
- package/dist/esm/solana/layout.js +155 -0
- package/dist/esm/solana/timelockIDL.js +420 -0
- package/dist/{solana → esm/solana}/types.d.ts +38 -37
- package/dist/esm/solana/types.js +101 -0
- package/dist/{solana → esm/solana}/utils.d.ts +4 -1
- package/dist/esm/solana/utils.js +123 -0
- package/dist/{sui → esm/sui}/StreamClient.d.ts +3 -3
- package/dist/esm/sui/StreamClient.js +403 -0
- package/dist/{sui → esm/sui}/constants.d.ts +1 -1
- package/dist/esm/sui/constants.js +39 -0
- package/dist/esm/sui/index.d.ts +4 -0
- package/dist/esm/sui/index.js +4 -0
- package/dist/{sui → esm/sui}/types.d.ts +13 -13
- package/dist/esm/sui/types.js +104 -0
- package/dist/{sui → esm/sui}/utils.d.ts +1 -1
- package/dist/esm/sui/utils.js +23 -0
- package/dist/{sui → esm/sui}/wallet.d.ts +1 -1
- package/dist/esm/sui/wallet.js +38 -0
- package/package.json +37 -35
- package/dist/__tests__/aptos/streamClient.spec.js +0 -161
- package/dist/__tests__/common/GenericStreamClient.spec.js +0 -44
- package/dist/aptos/StreamClient.js +0 -431
- package/dist/aptos/constants.js +0 -28
- package/dist/aptos/index.d.ts +0 -4
- package/dist/aptos/types.js +0 -77
- package/dist/aptos/wallet.js +0 -89
- package/dist/common/BaseStreamClient.js +0 -71
- package/dist/common/GenericStreamClient.js +0 -128
- package/dist/common/constants.d.ts +0 -3
- package/dist/common/utils.js +0 -118
- package/dist/evm/StreamClient.js +0 -496
- package/dist/evm/constants.js +0 -39
- package/dist/evm/index.d.ts +0 -5
- package/dist/index.d.ts +0 -9
- package/dist/solana/StreamClient.js +0 -1253
- package/dist/solana/index.d.ts +0 -7
- package/dist/solana/index.js +0 -43
- package/dist/solana/utils.js +0 -211
- package/dist/sui/StreamClient.js +0 -648
- package/dist/sui/constants.js +0 -43
- package/dist/sui/index.d.ts +0 -4
- package/dist/sui/types.js +0 -102
- package/dist/sui/wallet.js +0 -90
- /package/dist/{common → cjs/common}/types.js +0 -0
- /package/dist/{evm → cjs/evm}/abi.js +0 -0
- /package/dist/{evm → cjs/evm}/ercAbi.js +0 -0
- /package/dist/{solana → cjs/solana}/instructionTypes.js +0 -0
- /package/dist/{solana → cjs/solana}/timelockIDL.js +0 -0
- /package/dist/{__tests__ → esm/__tests__}/aptos/streamClient.spec.d.ts +0 -0
- /package/dist/{__tests__ → esm/__tests__}/common/GenericStreamClient.spec.d.ts +0 -0
- /package/dist/{aptos → esm/aptos}/utils.d.ts +0 -0
- /package/dist/{aptos → esm/aptos}/wallet.d.ts +0 -0
- /package/dist/{evm → esm/evm}/abi.d.ts +0 -0
- /package/dist/{evm → esm/evm}/ercAbi.d.ts +0 -0
- /package/dist/{evm → esm/evm}/utils.d.ts +0 -0
- /package/dist/{solana → esm/solana}/instructionTypes.d.ts +0 -0
- /package/dist/{solana → esm/solana}/timelockIDL.d.ts +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.SOLANA_ERROR_MAP = exports.SOLANA_ERROR_MATCH_REGEX = exports.PARTNERS_SCHEMA = exports.PARTNER_SCHEMA = exports.AIRDROP_AMOUNT = exports.DEFAULT_STREAMFLOW_FEE = exports.FEES_METADATA_SEED = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.PARTNER_ORACLE_PROGRAM_ID = exports.PROGRAM_ID = exports.CREATE_PARAMS_PADDING = exports.STREAM_STRUCT_OFFSETS = exports.STREAM_STRUCT_OFFSET_MINT = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const buffer_1 = require("buffer");
|
|
6
|
+
const types_js_1 = require("../common/types.js");
|
|
7
7
|
exports.TX_FINALITY_CONFIRMED = "confirmed";
|
|
8
8
|
exports.STREAM_STRUCT_OFFSET_SENDER = 49;
|
|
9
9
|
exports.STREAM_STRUCT_OFFSET_RECIPIENT = 113;
|
|
@@ -15,18 +15,18 @@ exports.STREAM_STRUCT_OFFSETS = {
|
|
|
15
15
|
};
|
|
16
16
|
// Defined: https://github.com/streamflow-finance/protocol/blob/main/programs/protocol/src/state.rs#L25
|
|
17
17
|
exports.CREATE_PARAMS_PADDING = 126;
|
|
18
|
-
exports.PROGRAM_ID =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
exports.PROGRAM_ID = {
|
|
19
|
+
[types_js_1.ICluster.Devnet]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
|
|
20
|
+
[types_js_1.ICluster.Mainnet]: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m",
|
|
21
|
+
[types_js_1.ICluster.Testnet]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
|
|
22
|
+
[types_js_1.ICluster.Local]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
|
|
23
|
+
};
|
|
24
24
|
exports.PARTNER_ORACLE_PROGRAM_ID = "pardpVtPjC8nLj1Dwncew62mUzfChdCX1EaoZe8oCAa";
|
|
25
25
|
exports.STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js_1.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
|
|
26
26
|
exports.WITHDRAWOR_PUBLIC_KEY = new web3_js_1.PublicKey("wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u");
|
|
27
27
|
exports.FEE_ORACLE_PUBLIC_KEY = new web3_js_1.PublicKey("B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT");
|
|
28
28
|
exports.AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
|
|
29
|
-
exports.FEES_METADATA_SEED = Buffer.from("strm_fees");
|
|
29
|
+
exports.FEES_METADATA_SEED = buffer_1.Buffer.from("strm_fees");
|
|
30
30
|
exports.DEFAULT_STREAMFLOW_FEE = 0.99;
|
|
31
31
|
exports.AIRDROP_AMOUNT = 1; // 1 SOL is the cap on the testnet
|
|
32
32
|
exports.PARTNER_SCHEMA = {
|
|
@@ -39,27 +39,27 @@ exports.PARTNER_SCHEMA = {
|
|
|
39
39
|
exports.PARTNERS_SCHEMA = { array: { type: exports.PARTNER_SCHEMA } };
|
|
40
40
|
exports.SOLANA_ERROR_MATCH_REGEX = /custom program error: (0x\d{2})/;
|
|
41
41
|
exports.SOLANA_ERROR_MAP = {
|
|
42
|
-
0x60:
|
|
43
|
-
0x61:
|
|
44
|
-
0x62:
|
|
45
|
-
0x63:
|
|
46
|
-
0x64:
|
|
47
|
-
0x65:
|
|
48
|
-
0x66:
|
|
49
|
-
0x67:
|
|
50
|
-
0x68:
|
|
51
|
-
0x69:
|
|
52
|
-
0x70:
|
|
53
|
-
0x71:
|
|
54
|
-
0x72:
|
|
55
|
-
0x73:
|
|
56
|
-
0x74:
|
|
57
|
-
0x80:
|
|
58
|
-
0x81:
|
|
59
|
-
0x82:
|
|
60
|
-
0x83:
|
|
61
|
-
0x84:
|
|
62
|
-
0x85:
|
|
63
|
-
0x86:
|
|
64
|
-
0x87:
|
|
42
|
+
0x60: types_js_1.SolanaContractErrorCode.AccountsNotWritable,
|
|
43
|
+
0x61: types_js_1.SolanaContractErrorCode.InvalidMetadata,
|
|
44
|
+
0x62: types_js_1.SolanaContractErrorCode.InvalidMetadataAccount,
|
|
45
|
+
0x63: types_js_1.SolanaContractErrorCode.MetadataAccountMismatch,
|
|
46
|
+
0x64: types_js_1.SolanaContractErrorCode.InvalidEscrowAccount,
|
|
47
|
+
0x65: types_js_1.SolanaContractErrorCode.NotAssociated,
|
|
48
|
+
0x66: types_js_1.SolanaContractErrorCode.MintMismatch,
|
|
49
|
+
0x67: types_js_1.SolanaContractErrorCode.TransferNotAllowed,
|
|
50
|
+
0x68: types_js_1.SolanaContractErrorCode.ContractClosed,
|
|
51
|
+
0x69: types_js_1.SolanaContractErrorCode.InvalidTreasury,
|
|
52
|
+
0x70: types_js_1.SolanaContractErrorCode.InvalidTimestamps,
|
|
53
|
+
0x71: types_js_1.SolanaContractErrorCode.InvalidDepositConfiguration,
|
|
54
|
+
0x72: types_js_1.SolanaContractErrorCode.AmountIsZero,
|
|
55
|
+
0x73: types_js_1.SolanaContractErrorCode.AmountMoreThanAvailable,
|
|
56
|
+
0x74: types_js_1.SolanaContractErrorCode.AmountAvailableIsZero,
|
|
57
|
+
0x80: types_js_1.SolanaContractErrorCode.ArithmeticError,
|
|
58
|
+
0x81: types_js_1.SolanaContractErrorCode.InvalidMetadataSize,
|
|
59
|
+
0x82: types_js_1.SolanaContractErrorCode.UninitializedMetadata,
|
|
60
|
+
0x83: types_js_1.SolanaContractErrorCode.Unauthorized,
|
|
61
|
+
0x84: types_js_1.SolanaContractErrorCode.SelfTransfer,
|
|
62
|
+
0x85: types_js_1.SolanaContractErrorCode.AlreadyPaused,
|
|
63
|
+
0x86: types_js_1.SolanaContractErrorCode.NotPaused,
|
|
64
|
+
0x87: types_js_1.SolanaContractErrorCode.MetadataNotRentExempt,
|
|
65
65
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.timelockIDL = exports.constants = void 0;
|
|
33
|
+
__exportStar(require("./StreamClient.js"), exports);
|
|
34
|
+
__exportStar(require("./utils.js"), exports);
|
|
35
|
+
__exportStar(require("./types.js"), exports);
|
|
36
|
+
__exportStar(require("./instructions.js"), exports);
|
|
37
|
+
exports.constants = __importStar(require("./constants.js"));
|
|
38
|
+
var timelockIDL_js_1 = require("./timelockIDL.js");
|
|
39
|
+
Object.defineProperty(exports, "timelockIDL", { enumerable: true, get: function () { return __importDefault(timelockIDL_js_1).default; } });
|
|
@@ -24,12 +24,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.updateStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
const buffer_1 = require("buffer");
|
|
28
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
29
|
+
const node_crypto_1 = require("node:crypto");
|
|
30
|
+
const Layout = __importStar(require("./layout.js"));
|
|
31
|
+
const utils_js_1 = require("./utils.js");
|
|
32
|
+
const hasher = () => (0, node_crypto_1.createHash)("sha256");
|
|
33
|
+
const sha256 = {
|
|
34
|
+
digest: (data) => new Uint8Array(hasher().update(data).digest()),
|
|
35
|
+
};
|
|
36
|
+
const createStreamInstruction = (data, programId, accounts) => {
|
|
37
|
+
const keys = [
|
|
33
38
|
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
34
39
|
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
35
40
|
{ pubkey: accounts.recipient, isSigner: false, isWritable: true },
|
|
@@ -61,16 +66,16 @@ var createStreamInstruction = function (data, programId, accounts) {
|
|
|
61
66
|
},
|
|
62
67
|
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
|
|
63
68
|
];
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
start_time:
|
|
69
|
-
net_amount_deposited:
|
|
70
|
-
period:
|
|
71
|
-
amount_per_period:
|
|
72
|
-
cliff:
|
|
73
|
-
cliff_amount:
|
|
69
|
+
let bufferData = buffer_1.Buffer.alloc(Layout.createStreamLayout.span);
|
|
70
|
+
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
71
|
+
const streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
72
|
+
const decodedData = {
|
|
73
|
+
start_time: (0, utils_js_1.toBuffer)(data.start),
|
|
74
|
+
net_amount_deposited: (0, utils_js_1.toBuffer)(data.depositedAmount),
|
|
75
|
+
period: (0, utils_js_1.toBuffer)(data.period),
|
|
76
|
+
amount_per_period: (0, utils_js_1.toBuffer)(data.amountPerPeriod),
|
|
77
|
+
cliff: (0, utils_js_1.toBuffer)(data.cliff),
|
|
78
|
+
cliff_amount: (0, utils_js_1.toBuffer)(data.cliffAmount),
|
|
74
79
|
cancelable_by_sender: Number(data.cancelableBySender),
|
|
75
80
|
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
76
81
|
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
@@ -82,20 +87,20 @@ var createStreamInstruction = function (data, programId, accounts) {
|
|
|
82
87
|
_can_update_rate_discriminator: 1,
|
|
83
88
|
pausable: Number(data.canPause),
|
|
84
89
|
stream_name: streamNameBuffer,
|
|
85
|
-
withdraw_frequency:
|
|
90
|
+
withdraw_frequency: (0, utils_js_1.toBuffer)(data.withdrawFrequency),
|
|
86
91
|
};
|
|
87
|
-
|
|
92
|
+
const encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
|
|
88
93
|
bufferData = bufferData.slice(0, encodeLength);
|
|
89
|
-
bufferData = buffer_1.Buffer.concat([buffer_1.Buffer.from(
|
|
94
|
+
bufferData = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:create")).slice(0, 8), bufferData, buffer_1.Buffer.alloc(10)]);
|
|
90
95
|
return new web3_js_1.TransactionInstruction({
|
|
91
|
-
keys
|
|
92
|
-
programId
|
|
96
|
+
keys,
|
|
97
|
+
programId,
|
|
93
98
|
data: bufferData,
|
|
94
99
|
});
|
|
95
100
|
};
|
|
96
101
|
exports.createStreamInstruction = createStreamInstruction;
|
|
97
|
-
|
|
98
|
-
|
|
102
|
+
const createUncheckedStreamInstruction = (data, programId, accounts) => {
|
|
103
|
+
const keys = [
|
|
99
104
|
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
100
105
|
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
101
106
|
{ pubkey: accounts.metadata, isSigner: false, isWritable: true },
|
|
@@ -115,16 +120,16 @@ var createUncheckedStreamInstruction = function (data, programId, accounts) {
|
|
|
115
120
|
isWritable: true,
|
|
116
121
|
});
|
|
117
122
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
start_time:
|
|
123
|
-
net_amount_deposited:
|
|
124
|
-
period:
|
|
125
|
-
amount_per_period:
|
|
126
|
-
cliff:
|
|
127
|
-
cliff_amount:
|
|
123
|
+
let bufferData = buffer_1.Buffer.alloc(Layout.createUncheckedStreamLayout.span);
|
|
124
|
+
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
125
|
+
const streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
126
|
+
const decodedData = {
|
|
127
|
+
start_time: (0, utils_js_1.toBuffer)(data.start),
|
|
128
|
+
net_amount_deposited: (0, utils_js_1.toBuffer)(data.depositedAmount),
|
|
129
|
+
period: (0, utils_js_1.toBuffer)(data.period),
|
|
130
|
+
amount_per_period: (0, utils_js_1.toBuffer)(data.amountPerPeriod),
|
|
131
|
+
cliff: (0, utils_js_1.toBuffer)(data.cliff),
|
|
132
|
+
cliff_amount: (0, utils_js_1.toBuffer)(data.cliffAmount),
|
|
128
133
|
cancelable_by_sender: Number(data.cancelableBySender),
|
|
129
134
|
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
130
135
|
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
@@ -132,28 +137,27 @@ var createUncheckedStreamInstruction = function (data, programId, accounts) {
|
|
|
132
137
|
transferable_by_recipient: Number(data.transferableByRecipient),
|
|
133
138
|
can_topup: Number(data.canTopup),
|
|
134
139
|
stream_name: streamNameBuffer,
|
|
135
|
-
withdraw_frequency:
|
|
140
|
+
withdraw_frequency: (0, utils_js_1.toBuffer)(data.withdrawFrequency),
|
|
136
141
|
recipient: data.recipient.toBuffer(),
|
|
137
142
|
partner: data.partner.toBuffer(),
|
|
138
143
|
pausable: Number(data.canPause),
|
|
139
144
|
can_update_rate: Number(data.canUpdateRate),
|
|
140
145
|
};
|
|
141
|
-
|
|
146
|
+
const encodeLength = Layout.createUncheckedStreamLayout.encode(decodedData, bufferData);
|
|
142
147
|
bufferData = bufferData.slice(0, encodeLength);
|
|
143
|
-
|
|
144
|
-
?
|
|
145
|
-
:
|
|
148
|
+
const digest = accounts.payer
|
|
149
|
+
? sha256.digest("global:create_unchecked_with_payer")
|
|
150
|
+
: sha256.digest("global:create_unchecked");
|
|
146
151
|
bufferData = buffer_1.Buffer.concat([buffer_1.Buffer.from(digest).slice(0, 8), bufferData, buffer_1.Buffer.alloc(10)]);
|
|
147
152
|
return new web3_js_1.TransactionInstruction({
|
|
148
|
-
keys
|
|
149
|
-
programId
|
|
153
|
+
keys,
|
|
154
|
+
programId,
|
|
150
155
|
data: bufferData,
|
|
151
156
|
});
|
|
152
157
|
};
|
|
153
158
|
exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
var keys = [
|
|
159
|
+
const withdrawStreamInstruction = (amount, programId, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }) => {
|
|
160
|
+
const keys = [
|
|
157
161
|
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
158
162
|
{ pubkey: recipient, isSigner: false, isWritable: true },
|
|
159
163
|
{ pubkey: recipientTokens, isSigner: false, isWritable: true },
|
|
@@ -170,35 +174,34 @@ var withdrawStreamInstruction = function (amount, programId, _a) {
|
|
|
170
174
|
{ pubkey: mint, isSigner: false, isWritable: true },
|
|
171
175
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
172
176
|
];
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
177
|
+
let data = buffer_1.Buffer.alloc(Layout.withdrawStreamLayout.span);
|
|
178
|
+
const decodedData = { amount: (0, utils_js_1.toBuffer)(amount) };
|
|
179
|
+
const encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
|
|
176
180
|
data = data.slice(0, encodeLength);
|
|
177
|
-
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(
|
|
181
|
+
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:withdraw")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
|
|
178
182
|
return new web3_js_1.TransactionInstruction({
|
|
179
|
-
keys
|
|
180
|
-
programId
|
|
181
|
-
data
|
|
183
|
+
keys,
|
|
184
|
+
programId,
|
|
185
|
+
data,
|
|
182
186
|
});
|
|
183
187
|
};
|
|
184
188
|
exports.withdrawStreamInstruction = withdrawStreamInstruction;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
var keys = [
|
|
189
|
+
const updateStreamInstruction = (params, programId, { authority, metadata, withdrawor, systemProgram }) => {
|
|
190
|
+
const keys = [
|
|
188
191
|
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
189
192
|
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
190
193
|
{ pubkey: withdrawor, isSigner: false, isWritable: true },
|
|
191
194
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
192
195
|
];
|
|
193
|
-
|
|
194
|
-
|
|
196
|
+
let data = buffer_1.Buffer.alloc(100);
|
|
197
|
+
const decodedData = {
|
|
195
198
|
enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
|
|
196
|
-
withdraw_frequency: params.withdrawFrequency ?
|
|
197
|
-
amount_per_period: params.amountPerPeriod ?
|
|
199
|
+
withdraw_frequency: params.withdrawFrequency ? (0, utils_js_1.toBuffer)(params.withdrawFrequency) : undefined,
|
|
200
|
+
amount_per_period: params.amountPerPeriod ? (0, utils_js_1.toBuffer)(params.amountPerPeriod) : undefined,
|
|
198
201
|
};
|
|
199
|
-
|
|
202
|
+
const encodeLength = Layout.encodeUpdateStream(decodedData, data);
|
|
200
203
|
data = data.slice(0, encodeLength);
|
|
201
|
-
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(
|
|
204
|
+
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:update")).slice(0, 8), data, buffer_1.Buffer.alloc(20)]);
|
|
202
205
|
return new web3_js_1.TransactionInstruction({
|
|
203
206
|
keys: keys,
|
|
204
207
|
programId: programId,
|
|
@@ -206,9 +209,8 @@ var updateStreamInstruction = function (params, programId, _a) {
|
|
|
206
209
|
});
|
|
207
210
|
};
|
|
208
211
|
exports.updateStreamInstruction = updateStreamInstruction;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
var keys = [
|
|
212
|
+
const cancelStreamInstruction = (programId, { authority, sender, senderTokens, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }) => {
|
|
213
|
+
const keys = [
|
|
212
214
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
213
215
|
{ pubkey: sender, isSigner: false, isWritable: true },
|
|
214
216
|
{ pubkey: senderTokens, isSigner: false, isWritable: true },
|
|
@@ -227,17 +229,16 @@ var cancelStreamInstruction = function (programId, _a) {
|
|
|
227
229
|
{ pubkey: mint, isSigner: false, isWritable: true },
|
|
228
230
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
229
231
|
];
|
|
230
|
-
|
|
232
|
+
const data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:cancel")).slice(0, 8), buffer_1.Buffer.alloc(10)]);
|
|
231
233
|
return new web3_js_1.TransactionInstruction({
|
|
232
|
-
keys
|
|
233
|
-
programId
|
|
234
|
-
data
|
|
234
|
+
keys,
|
|
235
|
+
programId,
|
|
236
|
+
data,
|
|
235
237
|
});
|
|
236
238
|
};
|
|
237
239
|
exports.cancelStreamInstruction = cancelStreamInstruction;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
var keys = [
|
|
240
|
+
const transferStreamInstruction = (programId, { authority, newRecipient, newRecipientTokens, metadata, mint, rent, tokenProgram, associatedTokenProgram, systemProgram, }) => {
|
|
241
|
+
const keys = [
|
|
241
242
|
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
242
243
|
{ pubkey: newRecipient, isSigner: false, isWritable: true },
|
|
243
244
|
{ pubkey: newRecipientTokens, isSigner: false, isWritable: true },
|
|
@@ -248,17 +249,16 @@ var transferStreamInstruction = function (programId, _a) {
|
|
|
248
249
|
{ pubkey: associatedTokenProgram, isSigner: false, isWritable: false },
|
|
249
250
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
250
251
|
];
|
|
251
|
-
|
|
252
|
+
const data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:transfer_recipient")).slice(0, 8), buffer_1.Buffer.alloc(10)]);
|
|
252
253
|
return new web3_js_1.TransactionInstruction({
|
|
253
|
-
keys
|
|
254
|
-
programId
|
|
255
|
-
data
|
|
254
|
+
keys,
|
|
255
|
+
programId,
|
|
256
|
+
data,
|
|
256
257
|
});
|
|
257
258
|
};
|
|
258
259
|
exports.transferStreamInstruction = transferStreamInstruction;
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
var keys = [
|
|
260
|
+
const topupStreamInstruction = (amount, programId, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }) => {
|
|
261
|
+
const keys = [
|
|
262
262
|
{ pubkey: sender, isSigner: true, isWritable: true },
|
|
263
263
|
{ pubkey: senderTokens, isSigner: false, isWritable: true },
|
|
264
264
|
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
@@ -276,15 +276,15 @@ var topupStreamInstruction = function (amount, programId, _a) {
|
|
|
276
276
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
277
277
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
278
278
|
];
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
279
|
+
let data = buffer_1.Buffer.alloc(Layout.topupStreamLayout.span);
|
|
280
|
+
const decodedData = { amount: (0, utils_js_1.toBuffer)(amount) };
|
|
281
|
+
const encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
|
|
282
282
|
data = data.slice(0, encodeLength);
|
|
283
|
-
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(
|
|
283
|
+
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:topup")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
|
|
284
284
|
return new web3_js_1.TransactionInstruction({
|
|
285
|
-
keys
|
|
286
|
-
programId
|
|
287
|
-
data
|
|
285
|
+
keys,
|
|
286
|
+
programId,
|
|
287
|
+
data,
|
|
288
288
|
});
|
|
289
289
|
};
|
|
290
290
|
exports.topupStreamInstruction = topupStreamInstruction;
|
|
@@ -24,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.topupStreamLayout = exports.encodeUpdateStream = exports.withdrawStreamLayout = exports.createUncheckedStreamLayout = exports.createStreamLayout = exports.partnerLayout = exports.streamLayout = void 0;
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const BufferLayout = __importStar(require("@solana/buffer-layout"));
|
|
28
|
+
const constants_js_1 = require("./constants.js");
|
|
29
29
|
/**
|
|
30
30
|
* Stream layout
|
|
31
31
|
*/
|
|
@@ -72,7 +72,7 @@ exports.streamLayout = BufferLayout.struct([
|
|
|
72
72
|
BufferLayout.u8("pausable"),
|
|
73
73
|
BufferLayout.u8("can_update_rate"),
|
|
74
74
|
BufferLayout.blob(4, "create_stream_params_padding_length"),
|
|
75
|
-
BufferLayout.seq(BufferLayout.u8(),
|
|
75
|
+
BufferLayout.seq(BufferLayout.u8(), constants_js_1.CREATE_PARAMS_PADDING, "create_params_padding"),
|
|
76
76
|
BufferLayout.u8("closed"),
|
|
77
77
|
BufferLayout.blob(8, "current_pause_start"),
|
|
78
78
|
BufferLayout.blob(8, "pause_cumulative"),
|
|
@@ -141,9 +141,8 @@ exports.withdrawStreamLayout = BufferLayout.struct([
|
|
|
141
141
|
/**
|
|
142
142
|
* Encode stream instruction layout
|
|
143
143
|
*/
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
var structs = [];
|
|
144
|
+
const encodeUpdateStream = (values, data) => {
|
|
145
|
+
const structs = [];
|
|
147
146
|
if (values.enable_automatic_withdrawal) {
|
|
148
147
|
structs.push(BufferLayout.u8("enable_automatic_withdrawal_exists"));
|
|
149
148
|
structs.push(BufferLayout.u8("enable_automatic_withdrawal"));
|
|
@@ -167,11 +166,11 @@ var encodeUpdateStream = function (values, data) {
|
|
|
167
166
|
}
|
|
168
167
|
return BufferLayout.struct(structs).encode({
|
|
169
168
|
enable_automatic_withdrawal_exists: values.enable_automatic_withdrawal ? 1 : 0,
|
|
170
|
-
enable_automatic_withdrawal:
|
|
169
|
+
enable_automatic_withdrawal: values.enable_automatic_withdrawal ?? 0,
|
|
171
170
|
withdraw_frequency_exists: values.withdraw_frequency ? 1 : 0,
|
|
172
|
-
withdraw_frequency:
|
|
171
|
+
withdraw_frequency: values.withdraw_frequency ?? 0,
|
|
173
172
|
amount_per_period_exists: values.amount_per_period ? 1 : 0,
|
|
174
|
-
amount_per_period:
|
|
173
|
+
amount_per_period: values.amount_per_period ?? 0,
|
|
175
174
|
}, data);
|
|
176
175
|
};
|
|
177
176
|
exports.encodeUpdateStream = encodeUpdateStream;
|
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.Contract = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var _a;
|
|
4
|
+
const contractUtils_js_1 = require("../common/contractUtils.js");
|
|
5
|
+
const utils_js_1 = require("../common/utils.js");
|
|
6
|
+
class Contract {
|
|
7
|
+
constructor(stream) {
|
|
20
8
|
this.magic = stream.magic.toNumber();
|
|
21
9
|
this.version = stream.version.toNumber();
|
|
22
10
|
this.createdAt = stream.createdAt.toNumber();
|
|
@@ -39,7 +27,7 @@ var Contract = /** @class */ (function () {
|
|
|
39
27
|
this.partnerFeeWithdrawn = stream.partnerFeeWithdrawn;
|
|
40
28
|
this.partnerFeePercent = stream.partnerFeePercent.toNumber();
|
|
41
29
|
this.partner = stream.partner.toBase58();
|
|
42
|
-
this.partnerTokens =
|
|
30
|
+
this.partnerTokens = stream.partnerTokens?.toBase58();
|
|
43
31
|
this.start = stream.start.toNumber();
|
|
44
32
|
this.depositedAmount = stream.depositedAmount;
|
|
45
33
|
this.period = stream.period.toNumber();
|
|
@@ -59,14 +47,16 @@ var Contract = /** @class */ (function () {
|
|
|
59
47
|
this.pauseCumulative = stream.pauseCumulative;
|
|
60
48
|
this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
|
|
61
49
|
this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
|
|
62
|
-
this.type = (0,
|
|
50
|
+
this.type = (0, contractUtils_js_1.buildStreamType)(this);
|
|
63
51
|
}
|
|
64
|
-
|
|
65
|
-
return (0,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
52
|
+
unlocked(currentTimestamp) {
|
|
53
|
+
return (0, contractUtils_js_1.calculateUnlockedAmount)({
|
|
54
|
+
...this,
|
|
55
|
+
currentTimestamp,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
remaining(decimals) {
|
|
59
|
+
return (0, utils_js_1.getNumberFromBigNumber)(this.depositedAmount.minus(this.withdrawnAmount), decimals);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
72
62
|
exports.Contract = Contract;
|