@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
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.extractSolanaErrorCode = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.decodeStream = exports.toBuffer = void 0;
|
|
7
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
8
|
+
const solana_1 = require("@streamflow/common/solana");
|
|
9
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
10
|
+
const layout_js_1 = require("./layout.js");
|
|
11
|
+
const constants_js_1 = require("./constants.js");
|
|
12
|
+
const decoder = new TextDecoder("utf-8");
|
|
13
|
+
const toUInt64String = (uintArr) => new DataView(uintArr.buffer, uintArr.byteOffset, uintArr.byteLength).getBigUint64(0, true).toString();
|
|
14
|
+
const toUInt8 = (uintArr) => new DataView(uintArr.buffer, uintArr.byteOffset, uintArr.byteLength).getUint8(0);
|
|
15
|
+
const toBuffer = (bigNumber) => {
|
|
16
|
+
const dv = new DataView(new ArrayBuffer(8), 0);
|
|
17
|
+
dv.setBigUint64(0, BigInt(bigNumber.integerValue().toString()), true);
|
|
18
|
+
return Buffer.from(dv.buffer);
|
|
19
|
+
};
|
|
20
|
+
exports.toBuffer = toBuffer;
|
|
21
|
+
const decodeStream = (buf) => {
|
|
22
|
+
const raw = layout_js_1.streamLayout.decode(buf);
|
|
23
|
+
return {
|
|
24
|
+
magic: (0, bignumber_js_1.default)(toUInt64String(raw.magic)),
|
|
25
|
+
version: (0, bignumber_js_1.default)(toUInt8(raw.version)),
|
|
26
|
+
createdAt: (0, bignumber_js_1.default)(toUInt64String(raw.created_at)),
|
|
27
|
+
withdrawnAmount: (0, bignumber_js_1.default)(toUInt64String(raw.withdrawn_amount)),
|
|
28
|
+
canceledAt: (0, bignumber_js_1.default)(toUInt64String(raw.canceled_at)),
|
|
29
|
+
end: (0, bignumber_js_1.default)(toUInt64String(raw.end_time)),
|
|
30
|
+
lastWithdrawnAt: (0, bignumber_js_1.default)(toUInt64String(raw.last_withdrawn_at)),
|
|
31
|
+
sender: new web3_js_1.PublicKey(raw.sender),
|
|
32
|
+
senderTokens: new web3_js_1.PublicKey(raw.sender_tokens),
|
|
33
|
+
recipient: new web3_js_1.PublicKey(raw.recipient),
|
|
34
|
+
recipientTokens: new web3_js_1.PublicKey(raw.recipient_tokens),
|
|
35
|
+
mint: new web3_js_1.PublicKey(raw.mint),
|
|
36
|
+
escrowTokens: new web3_js_1.PublicKey(raw.escrow_tokens),
|
|
37
|
+
streamflowTreasury: new web3_js_1.PublicKey(raw.streamflow_treasury),
|
|
38
|
+
streamflowTreasuryTokens: new web3_js_1.PublicKey(raw.streamflow_treasury_tokens),
|
|
39
|
+
streamflowFeeTotal: (0, bignumber_js_1.default)(toUInt64String(raw.streamflow_fee_total)),
|
|
40
|
+
streamflowFeeWithdrawn: (0, bignumber_js_1.default)(toUInt64String(raw.streamflow_fee_withdrawn)),
|
|
41
|
+
streamflowFeePercent: (0, bignumber_js_1.default)(raw.streamflow_fee_percent),
|
|
42
|
+
partnerFeeTotal: (0, bignumber_js_1.default)(toUInt64String(raw.partner_fee_total)),
|
|
43
|
+
partnerFeeWithdrawn: (0, bignumber_js_1.default)(toUInt64String(raw.partner_fee_withdrawn)),
|
|
44
|
+
partnerFeePercent: (0, bignumber_js_1.default)(raw.partner_fee_percent),
|
|
45
|
+
partner: new web3_js_1.PublicKey(raw.partner),
|
|
46
|
+
partnerTokens: new web3_js_1.PublicKey(raw.partner_tokens),
|
|
47
|
+
start: (0, bignumber_js_1.default)(toUInt64String(raw.start_time)),
|
|
48
|
+
depositedAmount: (0, bignumber_js_1.default)(toUInt64String(raw.net_amount_deposited)),
|
|
49
|
+
period: (0, bignumber_js_1.default)(toUInt64String(raw.period)),
|
|
50
|
+
amountPerPeriod: (0, bignumber_js_1.default)(toUInt64String(raw.amount_per_period)),
|
|
51
|
+
cliff: (0, bignumber_js_1.default)(toUInt64String(raw.cliff)),
|
|
52
|
+
cliffAmount: (0, bignumber_js_1.default)(toUInt64String(raw.cliff_amount)),
|
|
53
|
+
cancelableBySender: Boolean(raw.cancelable_by_sender),
|
|
54
|
+
cancelableByRecipient: Boolean(raw.cancelable_by_recipient),
|
|
55
|
+
automaticWithdrawal: Boolean(raw.automatic_withdrawal),
|
|
56
|
+
transferableBySender: Boolean(raw.transferable_by_sender),
|
|
57
|
+
transferableByRecipient: Boolean(raw.transferable_by_recipient),
|
|
58
|
+
canTopup: Boolean(raw.can_topup),
|
|
59
|
+
name: decoder.decode(raw.stream_name),
|
|
60
|
+
withdrawFrequency: (0, bignumber_js_1.default)(toUInt64String(raw.withdraw_frequency)),
|
|
61
|
+
closed: Boolean(raw.closed),
|
|
62
|
+
currentPauseStart: (0, bignumber_js_1.default)(toUInt64String(raw.current_pause_start)),
|
|
63
|
+
pauseCumulative: (0, bignumber_js_1.default)(toUInt64String(raw.pause_cumulative)),
|
|
64
|
+
lastRateChangeTime: (0, bignumber_js_1.default)(toUInt64String(raw.last_rate_change_time)),
|
|
65
|
+
fundsUnlockedAtLastRateChange: (0, bignumber_js_1.default)(toUInt64String(raw.funds_unlocked_at_last_rate_change)),
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
exports.decodeStream = decodeStream;
|
|
69
|
+
/**
|
|
70
|
+
* Sign passed BatchItems with wallet request or KeyPair
|
|
71
|
+
* @param {Keypair | SignerWalletAdapter} sender - Wallet or Keypair of sendin account
|
|
72
|
+
* @param {BatchItem[]} items - Multiple recipient contracts split into separate items
|
|
73
|
+
* @return {BatchItem[]} - Returns items with signatures.
|
|
74
|
+
*/
|
|
75
|
+
async function signAllTransactionWithRecipients(sender, items) {
|
|
76
|
+
const isKeypair = (0, solana_1.isSignerKeypair)(sender);
|
|
77
|
+
const isWallet = (0, solana_1.isSignerWallet)(sender);
|
|
78
|
+
if (isKeypair) {
|
|
79
|
+
return items.map((t) => {
|
|
80
|
+
t.tx.sign([sender]);
|
|
81
|
+
return { tx: t.tx, recipient: t.recipient };
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
else if (isWallet) {
|
|
85
|
+
const signedTxs = await sender.signAllTransactions(items.map((t) => t.tx));
|
|
86
|
+
return items.map((item, index) => ({
|
|
87
|
+
...item,
|
|
88
|
+
tx: signedTxs[index],
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// If signer is not passed
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
|
|
97
|
+
/**
|
|
98
|
+
* Sign passed BatchItems with wallet request or KeyPair
|
|
99
|
+
* @param {Connection} connection - Solana web3 connection object.
|
|
100
|
+
* @param {BatchItem} batchItem - Signed transaction ready to be send.
|
|
101
|
+
* @param confirmationParams - Confirmation Params that will be used for execution
|
|
102
|
+
* @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
|
|
103
|
+
* @return {Promise<BatchItemResult>} - Returns settled transaction item
|
|
104
|
+
*/
|
|
105
|
+
async function sendAndConfirmStreamRawTransaction(connection, batchItem, confirmationParams, throttleParams) {
|
|
106
|
+
try {
|
|
107
|
+
const completedTxSignature = await (0, solana_1.executeTransaction)(connection, batchItem.tx, confirmationParams, throttleParams);
|
|
108
|
+
return { ...batchItem, signature: completedTxSignature };
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
throw {
|
|
112
|
+
recipient: batchItem.recipient,
|
|
113
|
+
error,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;
|
|
118
|
+
function extractSolanaErrorCode(errorText, logs) {
|
|
119
|
+
let match = constants_js_1.SOLANA_ERROR_MATCH_REGEX.exec(errorText);
|
|
120
|
+
if (!match && logs) {
|
|
121
|
+
for (const logLine of logs) {
|
|
122
|
+
match = constants_js_1.SOLANA_ERROR_MATCH_REGEX.exec(logLine);
|
|
123
|
+
if (match !== null) {
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (!match) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
const errorCode = Number(match[1]);
|
|
132
|
+
return constants_js_1.SOLANA_ERROR_MAP[errorCode] || null;
|
|
133
|
+
}
|
|
134
|
+
exports.extractSolanaErrorCode = extractSolanaErrorCode;
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const client_1 = require("@mysten/sui.js/client");
|
|
4
|
+
const transactions_1 = require("@mysten/sui.js/transactions");
|
|
5
|
+
const utils_1 = require("@mysten/sui.js/utils");
|
|
6
|
+
const BaseStreamClient_js_1 = require("../common/BaseStreamClient.js");
|
|
7
|
+
const types_js_1 = require("../common/types.js");
|
|
8
|
+
const constants_js_1 = require("./constants.js");
|
|
9
|
+
const types_js_2 = require("./types.js");
|
|
10
|
+
const utils_js_1 = require("./utils.js");
|
|
11
|
+
const wallet_js_1 = require("./wallet.js");
|
|
12
|
+
const utils_js_2 = require("../common/utils.js");
|
|
13
|
+
const constants_js_2 = require("../common/constants.js");
|
|
14
|
+
class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
15
|
+
constructor(clusterUrl, cluster = types_js_1.ICluster.Mainnet, ids) {
|
|
16
|
+
super();
|
|
17
|
+
this.programId = ids?.program ? ids.program : constants_js_1.SUI_PROGRAM_IDS[cluster];
|
|
18
|
+
this.configId = ids?.config ? ids.config : constants_js_1.SUI_CONFIG_IDS[cluster];
|
|
19
|
+
this.feeTableId = ids?.feeTable ? ids.feeTable : constants_js_1.SUI_FEE_TABLE_IDS[cluster];
|
|
20
|
+
this.client = new client_1.SuiClient({ url: clusterUrl });
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new stream/vesting contract.
|
|
24
|
+
*/
|
|
25
|
+
async create(streamData, { senderWallet }) {
|
|
26
|
+
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
27
|
+
const totalFee = await this.getTotalFee({
|
|
28
|
+
address: streamData.partner ?? wallet.address,
|
|
29
|
+
});
|
|
30
|
+
const [txb] = await this.generateCreateBlock(wallet.address, {
|
|
31
|
+
...streamData,
|
|
32
|
+
recipients: [{ ...streamData }],
|
|
33
|
+
}, totalFee);
|
|
34
|
+
const { digest, events } = await wallet.signAndExecuteTransactionBlock({
|
|
35
|
+
transactionBlock: txb,
|
|
36
|
+
options: { showEvents: true },
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
ixs: [],
|
|
40
|
+
txId: digest,
|
|
41
|
+
metadataId: events[0].parsedJson.address,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Creates multiple stream/vesting contracts.
|
|
46
|
+
* We don't chain transactions in one Block so that one failed transaction does not revert all others.
|
|
47
|
+
*/
|
|
48
|
+
async createMultiple(multipleStreamData, { senderWallet }) {
|
|
49
|
+
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
50
|
+
const totalFee = await this.getTotalFee({
|
|
51
|
+
address: multipleStreamData.partner ?? wallet.address,
|
|
52
|
+
});
|
|
53
|
+
const [txb, firstIndex] = await this.generateCreateBlock(wallet.address, multipleStreamData, totalFee);
|
|
54
|
+
const txs = [];
|
|
55
|
+
const metadatas = [];
|
|
56
|
+
const metadataToRecipient = {};
|
|
57
|
+
const errors = [];
|
|
58
|
+
try {
|
|
59
|
+
const { digest, events, effects } = await wallet.signAndExecuteTransactionBlock({
|
|
60
|
+
transactionBlock: txb,
|
|
61
|
+
options: { showEffects: true, showEvents: true },
|
|
62
|
+
});
|
|
63
|
+
txs.push(digest);
|
|
64
|
+
if (effects.status.status === "failure") {
|
|
65
|
+
multipleStreamData.recipients.forEach((recipient) => {
|
|
66
|
+
errors.push({
|
|
67
|
+
error: effects.status.error ?? "Unknown error!",
|
|
68
|
+
recipient: recipient.recipient,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
multipleStreamData.recipients.forEach((recipient, index) => {
|
|
74
|
+
const metadataId = events[index].parsedJson.address;
|
|
75
|
+
metadatas.push(metadataId);
|
|
76
|
+
metadataToRecipient[metadataId] = recipient;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
const errorInfo = (0, utils_js_1.extractSuiErrorInfo)(e.toString() ?? "Unknown error!");
|
|
82
|
+
multipleStreamData.recipients.forEach((recipient, index) => {
|
|
83
|
+
if (errorInfo.index === undefined ||
|
|
84
|
+
errorInfo.index < index + firstIndex ||
|
|
85
|
+
errorInfo.index >= multipleStreamData.recipients.length + firstIndex ||
|
|
86
|
+
errorInfo.index === index + firstIndex) {
|
|
87
|
+
errors.push({
|
|
88
|
+
error: errorInfo.text,
|
|
89
|
+
recipient: recipient.recipient,
|
|
90
|
+
contractErrorCode: errorInfo.parsed?.name,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
txs,
|
|
97
|
+
metadatas,
|
|
98
|
+
metadataToRecipient,
|
|
99
|
+
errors,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Attempts withdrawing from the specified stream.
|
|
104
|
+
*/
|
|
105
|
+
async withdraw({ id, amount = constants_js_2.WITHDRAW_AVAILABLE_AMOUNT }, { senderWallet, tokenId }) {
|
|
106
|
+
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
107
|
+
const txb = new transactions_1.TransactionBlock();
|
|
108
|
+
txb.moveCall({
|
|
109
|
+
target: `${this.programId}::protocol::withdraw`,
|
|
110
|
+
typeArguments: [tokenId],
|
|
111
|
+
arguments: [
|
|
112
|
+
txb.object(id),
|
|
113
|
+
txb.object(this.configId),
|
|
114
|
+
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
115
|
+
txb.pure(amount.toString()),
|
|
116
|
+
],
|
|
117
|
+
});
|
|
118
|
+
const { digest } = await wallet.signAndExecuteTransactionBlock({
|
|
119
|
+
transactionBlock: txb,
|
|
120
|
+
});
|
|
121
|
+
return {
|
|
122
|
+
ixs: [],
|
|
123
|
+
txId: digest,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Attempts canceling the specified stream.
|
|
128
|
+
*/
|
|
129
|
+
async cancel(cancelData, { senderWallet, tokenId }) {
|
|
130
|
+
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
131
|
+
const txb = new transactions_1.TransactionBlock();
|
|
132
|
+
txb.moveCall({
|
|
133
|
+
target: `${this.programId}::protocol::cancel`,
|
|
134
|
+
typeArguments: [tokenId],
|
|
135
|
+
arguments: [txb.object(cancelData.id), txb.object(this.configId), txb.object(utils_1.SUI_CLOCK_OBJECT_ID)],
|
|
136
|
+
});
|
|
137
|
+
const { digest } = await wallet.signAndExecuteTransactionBlock({
|
|
138
|
+
transactionBlock: txb,
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
ixs: [],
|
|
142
|
+
txId: digest,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
147
|
+
*/
|
|
148
|
+
async transfer(transferData, { senderWallet, tokenId }) {
|
|
149
|
+
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
150
|
+
const txb = new transactions_1.TransactionBlock();
|
|
151
|
+
txb.moveCall({
|
|
152
|
+
target: `${this.programId}::protocol::transfer`,
|
|
153
|
+
typeArguments: [tokenId],
|
|
154
|
+
arguments: [txb.object(transferData.id), txb.pure(transferData.newRecipient)],
|
|
155
|
+
});
|
|
156
|
+
const { digest } = await wallet.signAndExecuteTransactionBlock({
|
|
157
|
+
transactionBlock: txb,
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
ixs: [],
|
|
161
|
+
txId: digest,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Tops up stream account with specified amount.
|
|
166
|
+
*/
|
|
167
|
+
async topup(topupData, { senderWallet, tokenId }) {
|
|
168
|
+
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
169
|
+
const txb = new transactions_1.TransactionBlock();
|
|
170
|
+
const coins = await this.getAllCoins(wallet.address, tokenId);
|
|
171
|
+
const stream = await this.getOne({ id: topupData.id });
|
|
172
|
+
const totalFee = (stream.partnerFeePercent + stream.streamflowFeePercent) / 100;
|
|
173
|
+
const coinObject = this.splitCoinObjectForAmount(txb, topupData.amount, tokenId, coins, totalFee);
|
|
174
|
+
txb.moveCall({
|
|
175
|
+
target: `${this.programId}::protocol::topup`,
|
|
176
|
+
typeArguments: [tokenId],
|
|
177
|
+
arguments: [
|
|
178
|
+
txb.object(topupData.id),
|
|
179
|
+
txb.object(this.configId),
|
|
180
|
+
coinObject,
|
|
181
|
+
txb.gas,
|
|
182
|
+
txb.pure(topupData.amount.toString()),
|
|
183
|
+
],
|
|
184
|
+
});
|
|
185
|
+
this.returnSplittedCoinObject(txb, tokenId, coins, coinObject);
|
|
186
|
+
const { digest } = await wallet.signAndExecuteTransactionBlock({
|
|
187
|
+
transactionBlock: txb,
|
|
188
|
+
});
|
|
189
|
+
return {
|
|
190
|
+
ixs: [],
|
|
191
|
+
txId: digest,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Fetch stream data by its id (address).
|
|
196
|
+
*/
|
|
197
|
+
async getOne({ id }) {
|
|
198
|
+
const response = await this.client.getObject({
|
|
199
|
+
id,
|
|
200
|
+
options: {
|
|
201
|
+
showContent: true,
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
if (!response.data) {
|
|
205
|
+
throw new Error(`Contract with id ${id} could not be found!`);
|
|
206
|
+
}
|
|
207
|
+
const content = response.data.content;
|
|
208
|
+
if (content.dataType !== "moveObject") {
|
|
209
|
+
throw new Error(`Not a Move Object!`);
|
|
210
|
+
}
|
|
211
|
+
return new types_js_2.Contract(content.fields, "0x97e9a9fb1392e9785319f5512d0bfde6ecf7757b09c6de41cec89e798dd361f2::strmt::STRMT");
|
|
212
|
+
}
|
|
213
|
+
async get() {
|
|
214
|
+
throw new Error("Get all method is not supported for Sui chain!");
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
218
|
+
*/
|
|
219
|
+
async update(updateData, { senderWallet, tokenId }) {
|
|
220
|
+
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
221
|
+
const txb = new transactions_1.TransactionBlock();
|
|
222
|
+
txb.moveCall({
|
|
223
|
+
target: `${this.programId}::protocol::update`,
|
|
224
|
+
typeArguments: [tokenId],
|
|
225
|
+
arguments: [
|
|
226
|
+
txb.object(updateData.id),
|
|
227
|
+
txb.object(this.configId),
|
|
228
|
+
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
229
|
+
txb.gas,
|
|
230
|
+
txb.pure(updateData.enableAutomaticWithdrawal !== undefined ? [updateData.enableAutomaticWithdrawal] : [], "vector<bool>"),
|
|
231
|
+
txb.pure(updateData.withdrawFrequency !== undefined ? [updateData.withdrawFrequency.toString()] : [], "vector<u64>"),
|
|
232
|
+
txb.pure(updateData.amountPerPeriod !== undefined ? [updateData.amountPerPeriod.toString()] : [], "vector<u64>"),
|
|
233
|
+
],
|
|
234
|
+
});
|
|
235
|
+
const { digest } = await wallet.signAndExecuteTransactionBlock({
|
|
236
|
+
transactionBlock: txb,
|
|
237
|
+
});
|
|
238
|
+
return {
|
|
239
|
+
ixs: [],
|
|
240
|
+
txId: digest,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
extractErrorCode(err) {
|
|
244
|
+
const errorInfo = (0, utils_js_1.extractSuiErrorInfo)(err.toString() ?? "Unknown error!");
|
|
245
|
+
return errorInfo?.parsed?.name || null;
|
|
246
|
+
}
|
|
247
|
+
async getFees({ address }) {
|
|
248
|
+
const response = await this.client.getObject({
|
|
249
|
+
id: this.feeTableId,
|
|
250
|
+
options: {
|
|
251
|
+
showContent: true,
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
const content = response.data.content;
|
|
255
|
+
if (content.dataType !== "moveObject") {
|
|
256
|
+
throw new Error(`Not a Move Object!`);
|
|
257
|
+
}
|
|
258
|
+
const fields = content.fields;
|
|
259
|
+
const fieldsResponse = await this.client.getDynamicFields({
|
|
260
|
+
parentId: fields.values.fields.id.id,
|
|
261
|
+
});
|
|
262
|
+
const partnerDynamicField = fieldsResponse.data.filter((item) => item.name.value === address)[0];
|
|
263
|
+
if (!partnerDynamicField) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
const valueResponse = await this.client.getObject({
|
|
267
|
+
id: partnerDynamicField.objectId,
|
|
268
|
+
options: {
|
|
269
|
+
showContent: true,
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
const valueContent = valueResponse.data.content;
|
|
273
|
+
if (valueContent.dataType !== "moveObject") {
|
|
274
|
+
throw new Error(`Not a Move Object!`);
|
|
275
|
+
}
|
|
276
|
+
const valueFields = valueContent.fields.value.fields;
|
|
277
|
+
return {
|
|
278
|
+
streamflowFee: Number(valueFields.streamflow_fee) / 100,
|
|
279
|
+
partnerFee: Number(valueFields.partner_fee) / 100,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
async getDefaultStreamflowFee() {
|
|
283
|
+
const response = await this.client.getObject({
|
|
284
|
+
id: this.configId,
|
|
285
|
+
options: {
|
|
286
|
+
showContent: true,
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
const content = response.data.content;
|
|
290
|
+
if (content.dataType !== "moveObject") {
|
|
291
|
+
throw new Error(`Not a Move Object!`);
|
|
292
|
+
}
|
|
293
|
+
const fields = content.fields;
|
|
294
|
+
return Number(fields.streamflow_fee) / 100;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Returns StreamClient protocol program ID.
|
|
298
|
+
*/
|
|
299
|
+
getProgramId() {
|
|
300
|
+
return this.programId;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Utility function to generate Transaction Block to create streams
|
|
304
|
+
*/
|
|
305
|
+
async generateCreateBlock(walletAddress, multipleStreamData, totalFee) {
|
|
306
|
+
let coins = await this.getAllCoins(walletAddress, multipleStreamData.tokenId);
|
|
307
|
+
const totalAmount = multipleStreamData.recipients
|
|
308
|
+
.map((recipiient) => recipiient.amount)
|
|
309
|
+
.reduce((prev, current) => current.plus(prev));
|
|
310
|
+
const txb = new transactions_1.TransactionBlock();
|
|
311
|
+
const coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins, totalFee);
|
|
312
|
+
coins = [coins[0]];
|
|
313
|
+
let firstIndex = null;
|
|
314
|
+
multipleStreamData.recipients.forEach((recipient) => {
|
|
315
|
+
const result = txb.moveCall({
|
|
316
|
+
target: `${this.programId}::protocol::create`,
|
|
317
|
+
typeArguments: [multipleStreamData.tokenId],
|
|
318
|
+
arguments: [
|
|
319
|
+
txb.object(this.configId),
|
|
320
|
+
txb.object(this.feeTableId),
|
|
321
|
+
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
322
|
+
coinObject,
|
|
323
|
+
txb.gas,
|
|
324
|
+
txb.pure(recipient.amount.toString()),
|
|
325
|
+
txb.pure(multipleStreamData.period),
|
|
326
|
+
txb.pure(recipient.amountPerPeriod.toString()),
|
|
327
|
+
txb.pure(multipleStreamData.start),
|
|
328
|
+
txb.pure(recipient.cliffAmount.toString()),
|
|
329
|
+
txb.pure(multipleStreamData.cancelableBySender),
|
|
330
|
+
txb.pure(multipleStreamData.cancelableByRecipient),
|
|
331
|
+
txb.pure(multipleStreamData.transferableBySender),
|
|
332
|
+
txb.pure(multipleStreamData.transferableByRecipient),
|
|
333
|
+
txb.pure(multipleStreamData.canTopup),
|
|
334
|
+
txb.pure(!!multipleStreamData.canPause),
|
|
335
|
+
txb.pure(!!multipleStreamData.canUpdateRate),
|
|
336
|
+
txb.pure(!!multipleStreamData.automaticWithdrawal),
|
|
337
|
+
txb.pure(multipleStreamData.withdrawalFrequency || 0),
|
|
338
|
+
txb.pure(recipient.name),
|
|
339
|
+
txb.pure(recipient.recipient),
|
|
340
|
+
txb.pure(multipleStreamData.partner || walletAddress),
|
|
341
|
+
],
|
|
342
|
+
});
|
|
343
|
+
if (result.kind === "Result" && firstIndex === null) {
|
|
344
|
+
firstIndex = result.index;
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
this.returnSplittedCoinObject(txb, multipleStreamData.tokenId, coins, coinObject);
|
|
348
|
+
return [txb, firstIndex];
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Returns all coins owned by a Wallet
|
|
352
|
+
* @param walletAddress wallet address
|
|
353
|
+
* @param coinType coin type
|
|
354
|
+
* @returns Array of Coin Structs
|
|
355
|
+
*/
|
|
356
|
+
async getAllCoins(walletAddress, coinType) {
|
|
357
|
+
let coinsResponse = await this.client.getCoins({
|
|
358
|
+
owner: walletAddress,
|
|
359
|
+
coinType: coinType,
|
|
360
|
+
});
|
|
361
|
+
const coins = coinsResponse.data;
|
|
362
|
+
while (coinsResponse.hasNextPage) {
|
|
363
|
+
coinsResponse = await this.client.getCoins({
|
|
364
|
+
owner: walletAddress,
|
|
365
|
+
coinType: coinType,
|
|
366
|
+
cursor: coinsResponse.nextCursor,
|
|
367
|
+
});
|
|
368
|
+
coins.push(...coinsResponse.data);
|
|
369
|
+
}
|
|
370
|
+
return coins;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Utility function to split Coin object and use splitted object for stream operations.
|
|
374
|
+
* We do it like thid to mitigate risk of Transaction reverting in case Stream is created for Sui Coin object.
|
|
375
|
+
* This way we can safely pass splitted Sui Coin object in Stream payload and use another object for gas/withdrawal fees.
|
|
376
|
+
* @param txb current transanction block
|
|
377
|
+
* @param amount minimal amount of coins requried
|
|
378
|
+
* @param coinType coin type
|
|
379
|
+
* @param coins array of owned coins of the same type
|
|
380
|
+
* @returns Coin Object to use in a Move Call
|
|
381
|
+
*/
|
|
382
|
+
splitCoinObjectForAmount(txb, amount, coinType, coins, totalFee) {
|
|
383
|
+
const coinObject = coinType === utils_1.SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
|
|
384
|
+
if (coins.length > 1) {
|
|
385
|
+
txb.mergeCoins(coinObject, coins.slice(1).map((item) => txb.object(item.coinObjectId)));
|
|
386
|
+
}
|
|
387
|
+
const totalAmount = (0, utils_js_2.calculateTotalAmountToDeposit)(amount, totalFee);
|
|
388
|
+
return txb.splitCoins(coinObject, [txb.pure(totalAmount.toString())])[0];
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Return previously splitted Coin Object to owner and merge it to to rebate storage fees
|
|
392
|
+
* @param txb current transanction block
|
|
393
|
+
* @param coinType coin type
|
|
394
|
+
* @param coinObject splitted object
|
|
395
|
+
* @param coins array of objects used in
|
|
396
|
+
*/
|
|
397
|
+
returnSplittedCoinObject(txb, coinType, coins, coinObject) {
|
|
398
|
+
const firstCoinObject = coinType === utils_1.SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
|
|
399
|
+
txb.mergeCoins(firstCoinObject, [coinObject]);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
exports.default = SuiStreamClient;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SUI_MODULE_ERROR_MAP = exports.SUI_ERROR_MATCH_REGEX = exports.SUI_FEE_TABLE_IDS = exports.SUI_CONFIG_IDS = exports.SUI_PROGRAM_IDS = void 0;
|
|
4
|
+
const types_js_1 = require("../common/types.js");
|
|
5
|
+
// TODO: remove Devnet and Local addresses as they are not deployed, they are just a copy Testnet values
|
|
6
|
+
exports.SUI_PROGRAM_IDS = {
|
|
7
|
+
[types_js_1.ICluster.Mainnet]: "0xe456a3a1d4e58e85b4b7175fabe6dae895b983f1379bb8948d6ec2f137b08a7b",
|
|
8
|
+
[types_js_1.ICluster.Devnet]: "0x34dacd839e1758ebb70bdcd4e08f18fbfef5e2b96d9aa7ce2b4a71d96ca0df5a",
|
|
9
|
+
[types_js_1.ICluster.Testnet]: "0x34dacd839e1758ebb70bdcd4e08f18fbfef5e2b96d9aa7ce2b4a71d96ca0df5a",
|
|
10
|
+
[types_js_1.ICluster.Local]: "0x34dacd839e1758ebb70bdcd4e08f18fbfef5e2b96d9aa7ce2b4a71d96ca0df5a",
|
|
11
|
+
};
|
|
12
|
+
exports.SUI_CONFIG_IDS = {
|
|
13
|
+
[types_js_1.ICluster.Mainnet]: "0x6cf6760b64245b8d23ef57c28ddceb6adbd540a23a509fef29b82237da4ab87b",
|
|
14
|
+
[types_js_1.ICluster.Devnet]: "0xd6c9f5074584f58074ce56e3c5cc436d82258ec3285f186a0d6438a60bacdbf8",
|
|
15
|
+
[types_js_1.ICluster.Testnet]: "0xd6c9f5074584f58074ce56e3c5cc436d82258ec3285f186a0d6438a60bacdbf8",
|
|
16
|
+
[types_js_1.ICluster.Local]: "0xd6c9f5074584f58074ce56e3c5cc436d82258ec3285f186a0d6438a60bacdbf8",
|
|
17
|
+
};
|
|
18
|
+
exports.SUI_FEE_TABLE_IDS = {
|
|
19
|
+
[types_js_1.ICluster.Mainnet]: "0xad9b75399632583fb9fcae6b5bcca34e6542ab3bedb630ecbd3f15cb1cc48dbe",
|
|
20
|
+
[types_js_1.ICluster.Devnet]: "0x6057b093904c5bdfec1067d2b8a4dc35f65bcab03b3029ad716c4882b0f36078",
|
|
21
|
+
[types_js_1.ICluster.Testnet]: "0x6057b093904c5bdfec1067d2b8a4dc35f65bcab03b3029ad716c4882b0f36078",
|
|
22
|
+
[types_js_1.ICluster.Local]: "0x6057b093904c5bdfec1067d2b8a4dc35f65bcab03b3029ad716c4882b0f36078",
|
|
23
|
+
};
|
|
24
|
+
exports.SUI_ERROR_MATCH_REGEX = /MoveAbort\(MoveLocation \{ module: ModuleId \{ address: (\w+), name: Identifier\("([\w_]+)"\) }, function: \d+, instruction: \d+, function_name: Some\("([\w_]+)"\) }, (\d+)\) in command (\d+)/;
|
|
25
|
+
exports.SUI_MODULE_ERROR_MAP = {
|
|
26
|
+
protocol: {
|
|
27
|
+
1: types_js_1.ContractErrorCode.ECONTRACT_NOT_INIT,
|
|
28
|
+
2: types_js_1.ContractErrorCode.EBAD_AMOUNT,
|
|
29
|
+
3: types_js_1.ContractErrorCode.ENO_PERMISSIONS,
|
|
30
|
+
4: types_js_1.ContractErrorCode.EBADINPUT,
|
|
31
|
+
5: types_js_1.ContractErrorCode.ECLOSED,
|
|
32
|
+
6: types_js_1.ContractErrorCode.EBAD_INPUT_AMOUNT_PER_PERIOD,
|
|
33
|
+
8: types_js_1.ContractErrorCode.EBAD_INPUT_UPDATE_RATE,
|
|
34
|
+
9: types_js_1.ContractErrorCode.EBAD_INPUT_CLIFF_AMOUNT,
|
|
35
|
+
10: types_js_1.ContractErrorCode.EBAD_INPUT_PERIOD,
|
|
36
|
+
11: types_js_1.ContractErrorCode.EBAD_INPUT_START,
|
|
37
|
+
13: types_js_1.ContractErrorCode.EBAD_INSUFFICIENT_WITHDRAWAL_FEES,
|
|
38
|
+
14: types_js_1.ContractErrorCode.EBAD_INSUFFICIENT_AMOUNT,
|
|
39
|
+
15: types_js_1.ContractErrorCode.EPAUSED,
|
|
40
|
+
16: types_js_1.ContractErrorCode.ENOTPAUSED,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -30,8 +30,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.constants = exports.SuiStreamClient = void 0;
|
|
33
|
-
var
|
|
34
|
-
Object.defineProperty(exports, "SuiStreamClient", { enumerable: true, get: function () { return __importDefault(
|
|
35
|
-
__exportStar(require("./utils"), exports);
|
|
36
|
-
__exportStar(require("./types"), exports);
|
|
37
|
-
exports.constants = __importStar(require("./constants"));
|
|
33
|
+
var StreamClient_js_1 = require("./StreamClient.js");
|
|
34
|
+
Object.defineProperty(exports, "SuiStreamClient", { enumerable: true, get: function () { return __importDefault(StreamClient_js_1).default; } });
|
|
35
|
+
__exportStar(require("./utils.js"), exports);
|
|
36
|
+
__exportStar(require("./types.js"), exports);
|
|
37
|
+
exports.constants = __importStar(require("./constants.js"));
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Contract = void 0;
|
|
7
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
+
const contractUtils_js_1 = require("../common/contractUtils.js");
|
|
9
|
+
const utils_js_1 = require("../common/utils.js");
|
|
10
|
+
class Contract {
|
|
11
|
+
constructor(stream, tokenId) {
|
|
12
|
+
const meta = stream.meta.fields;
|
|
13
|
+
const fees = stream.fees.fields;
|
|
14
|
+
this.magic = 0;
|
|
15
|
+
this.version = parseInt(stream.version);
|
|
16
|
+
this.createdAt = parseInt(stream.created);
|
|
17
|
+
this.withdrawnAmount = (0, bignumber_js_1.default)(stream.withdrawn);
|
|
18
|
+
this.canceledAt = parseInt(stream.canceled_at);
|
|
19
|
+
this.end = parseInt(stream.end);
|
|
20
|
+
this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
|
|
21
|
+
this.sender = stream.sender;
|
|
22
|
+
this.senderTokens = stream.sender;
|
|
23
|
+
this.recipient = stream.recipient;
|
|
24
|
+
this.recipientTokens = stream.recipient;
|
|
25
|
+
this.mint = tokenId;
|
|
26
|
+
this.escrowTokens = "";
|
|
27
|
+
this.streamflowTreasury = "";
|
|
28
|
+
this.streamflowTreasuryTokens = "";
|
|
29
|
+
this.streamflowFeeTotal = (0, bignumber_js_1.default)(0);
|
|
30
|
+
this.streamflowFeeWithdrawn = (0, bignumber_js_1.default)(0);
|
|
31
|
+
this.streamflowFeePercent = parseInt(fees.streamflow_fee_percentage) / 10000;
|
|
32
|
+
this.partnerFeeTotal = (0, bignumber_js_1.default)(0);
|
|
33
|
+
this.partnerFeeWithdrawn = (0, bignumber_js_1.default)(0);
|
|
34
|
+
this.partnerFeePercent = parseInt(fees.partner_fee_percentage) / 10000;
|
|
35
|
+
this.partner = stream.partner;
|
|
36
|
+
this.partnerTokens = "";
|
|
37
|
+
this.start = parseInt(stream.start);
|
|
38
|
+
this.depositedAmount = (0, bignumber_js_1.default)(stream.amount);
|
|
39
|
+
this.period = parseInt(stream.period);
|
|
40
|
+
this.amountPerPeriod = (0, bignumber_js_1.default)(stream.amount_per_period);
|
|
41
|
+
this.cliff = parseInt(stream.start);
|
|
42
|
+
this.cliffAmount = (0, bignumber_js_1.default)(stream.cliff_amount);
|
|
43
|
+
this.cancelableBySender = meta.cancelable_by_sender;
|
|
44
|
+
this.cancelableByRecipient = meta.cancelable_by_recipient;
|
|
45
|
+
this.automaticWithdrawal = meta.automatic_withdrawal;
|
|
46
|
+
this.transferableBySender = meta.transferable_by_sender;
|
|
47
|
+
this.transferableByRecipient = meta.transferable_by_recipient;
|
|
48
|
+
this.canTopup = meta.can_topup;
|
|
49
|
+
this.name = String.fromCharCode(...meta.contract_name);
|
|
50
|
+
this.withdrawalFrequency = parseInt(meta.withdrawal_frequency);
|
|
51
|
+
this.closed = stream.closed;
|
|
52
|
+
this.currentPauseStart = parseInt(stream.current_pause_start);
|
|
53
|
+
this.pauseCumulative = (0, bignumber_js_1.default)(stream.pause_cumulative);
|
|
54
|
+
this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
|
|
55
|
+
this.fundsUnlockedAtLastRateChange = (0, bignumber_js_1.default)(stream.funds_unlocked_at_last_rate_change);
|
|
56
|
+
this.type = (0, contractUtils_js_1.buildStreamType)(this);
|
|
57
|
+
}
|
|
58
|
+
unlocked(currentTimestamp) {
|
|
59
|
+
return (0, contractUtils_js_1.calculateUnlockedAmount)({
|
|
60
|
+
...this,
|
|
61
|
+
currentTimestamp,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
remaining(decimals) {
|
|
65
|
+
return (0, utils_js_1.getNumberFromBigNumber)(this.depositedAmount.minus(this.withdrawnAmount), decimals);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.Contract = Contract;
|