@streamflow/stream 5.6.2 → 5.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/aptos/streamClient.spec.d.ts +1 -0
- package/dist/__tests__/aptos/streamClient.spec.js +161 -0
- package/dist/__tests__/common/GenericStreamClient.spec.d.ts +1 -0
- package/dist/__tests__/common/GenericStreamClient.spec.js +44 -0
- package/dist/aptos/StreamClient.d.ts +51 -0
- package/dist/aptos/StreamClient.js +391 -0
- package/dist/aptos/constants.d.ts +8 -0
- package/dist/aptos/constants.js +28 -0
- package/dist/aptos/index.d.ts +2 -0
- package/dist/aptos/index.js +24 -0
- package/dist/aptos/types.d.ts +97 -0
- package/dist/aptos/types.js +76 -0
- package/dist/aptos/utils.d.ts +1 -0
- package/dist/aptos/utils.js +12 -0
- package/dist/aptos/wallet.d.ts +9 -0
- package/dist/aptos/wallet.js +89 -0
- package/dist/common/BaseStreamClient.d.ts +13 -0
- package/dist/common/BaseStreamClient.js +13 -0
- package/dist/common/GenericStreamClient.d.ts +93 -0
- package/dist/common/GenericStreamClient.js +114 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +4 -0
- package/dist/common/contractUtils.d.ts +47 -0
- package/dist/common/contractUtils.js +55 -0
- package/dist/common/types.d.ts +252 -0
- package/dist/common/types.js +165 -0
- package/dist/common/utils.d.ts +22 -0
- package/dist/common/utils.js +101 -0
- package/dist/evm/StreamClient.d.ts +30 -0
- package/dist/evm/StreamClient.js +461 -0
- package/dist/evm/abi.d.ts +111 -0
- package/dist/evm/abi.js +1257 -0
- package/dist/evm/constants.d.ts +20 -0
- package/dist/evm/constants.js +39 -0
- package/dist/evm/ercAbi.d.ts +39 -0
- package/dist/evm/ercAbi.js +224 -0
- package/dist/evm/index.d.ts +2 -0
- package/dist/evm/index.js +24 -0
- package/dist/evm/types.d.ts +93 -0
- package/dist/evm/types.js +75 -0
- package/dist/evm/utils.d.ts +1 -0
- package/dist/evm/utils.js +12 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +41 -0
- package/dist/solana/StreamClient.d.ts +72 -0
- package/dist/solana/StreamClient.js +927 -0
- package/dist/solana/constants.d.ts +22 -0
- package/dist/solana/constants.js +50 -0
- package/dist/solana/index.d.ts +7 -0
- package/dist/solana/index.js +43 -0
- package/dist/solana/instructionTypes.d.ts +96 -0
- package/dist/solana/instructionTypes.js +2 -0
- package/dist/solana/instructions.d.ts +139 -0
- package/dist/solana/instructions.js +407 -0
- package/dist/solana/layout.d.ts +27 -0
- package/dist/solana/layout.js +170 -0
- package/dist/solana/timelockIDL.d.ts +22 -0
- package/dist/solana/timelockIDL.js +422 -0
- package/dist/solana/types.d.ts +292 -0
- package/dist/solana/types.js +81 -0
- package/dist/solana/utils.d.ts +44 -0
- package/dist/solana/utils.js +303 -0
- package/dist/sui/StreamClient.d.ts +79 -0
- package/dist/sui/StreamClient.js +571 -0
- package/dist/sui/constants.d.ts +10 -0
- package/dist/sui/constants.js +43 -0
- package/dist/sui/index.d.ts +2 -0
- package/dist/sui/index.js +23 -0
- package/dist/sui/types.d.ts +141 -0
- package/dist/sui/types.js +102 -0
- package/dist/sui/utils.d.ts +2 -0
- package/dist/sui/utils.js +29 -0
- package/dist/sui/wallet.d.ts +11 -0
- package/dist/sui/wallet.js +75 -0
- package/package.json +2 -2
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.APTOS_MODULE_ERROR_MAP = exports.APTOS_ERROR_MATCH_REGEX = exports.APTOS_PROGRAM_IDS = void 0;
|
|
5
|
+
var types_1 = require("../common/types");
|
|
6
|
+
exports.APTOS_PROGRAM_IDS = (_a = {},
|
|
7
|
+
_a[types_1.ICluster.Mainnet] = "0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0",
|
|
8
|
+
// TODO: Add a correct programID for Test net
|
|
9
|
+
_a[types_1.ICluster.Devnet] = "0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688",
|
|
10
|
+
_a[types_1.ICluster.Testnet] = "0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688",
|
|
11
|
+
_a[types_1.ICluster.Local] = "0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0",
|
|
12
|
+
_a);
|
|
13
|
+
exports.APTOS_ERROR_MATCH_REGEX = /Move abort in [a-z0-9]+::([^:]+): ([A-Z_]+)/;
|
|
14
|
+
exports.APTOS_MODULE_ERROR_MAP = {
|
|
15
|
+
protocol: {
|
|
16
|
+
1: types_1.ContractErrorCode.ECONTRACT_NOT_INIT,
|
|
17
|
+
2: types_1.ContractErrorCode.EBAD_AMOUNT,
|
|
18
|
+
3: types_1.ContractErrorCode.ENO_PERMISSIONS,
|
|
19
|
+
4: types_1.ContractErrorCode.EBADINPUT,
|
|
20
|
+
5: types_1.ContractErrorCode.ECLOSED,
|
|
21
|
+
6: types_1.ContractErrorCode.EBAD_INPUT_AMOUNT_PER_PERIOD,
|
|
22
|
+
8: types_1.ContractErrorCode.EBAD_INPUT_UPDATE_RATE,
|
|
23
|
+
9: types_1.ContractErrorCode.EBAD_INPUT_CLIFF_AMOUNT,
|
|
24
|
+
10: types_1.ContractErrorCode.EBAD_INPUT_PERIOD,
|
|
25
|
+
11: types_1.ContractErrorCode.EBAD_INPUT_START,
|
|
26
|
+
12: types_1.ContractErrorCode.ENO_RECIPIENT_COIN_ADDRESS,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.AptosStreamClient = exports.default = void 0;
|
|
21
|
+
var StreamClient_1 = require("./StreamClient");
|
|
22
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
|
|
23
|
+
Object.defineProperty(exports, "AptosStreamClient", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
|
|
24
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { AptosAccount } from "aptos";
|
|
2
|
+
import { WalletContextState } from "@manahippo/aptos-wallet-adapter";
|
|
3
|
+
import BN from "bn.js";
|
|
4
|
+
import { Stream, StreamType } from "../common/types";
|
|
5
|
+
export interface ICreateStreamAptosExt {
|
|
6
|
+
senderWallet: WalletContextState | AptosAccount;
|
|
7
|
+
}
|
|
8
|
+
export declare type ITransactionAptosExt = ICreateStreamAptosExt & {
|
|
9
|
+
tokenId: string;
|
|
10
|
+
};
|
|
11
|
+
export interface StreamResource {
|
|
12
|
+
amount: string;
|
|
13
|
+
amount_per_period: string;
|
|
14
|
+
canceled_at: string;
|
|
15
|
+
cliff_amount: string;
|
|
16
|
+
closed: boolean;
|
|
17
|
+
contract_signer_cap: {
|
|
18
|
+
account: string;
|
|
19
|
+
};
|
|
20
|
+
created: string;
|
|
21
|
+
current_pause_start: string;
|
|
22
|
+
end: string;
|
|
23
|
+
fees: {
|
|
24
|
+
streamflow_fee: string;
|
|
25
|
+
streamflow_fee_percentage: string;
|
|
26
|
+
streamflow_fee_withdrawn: string;
|
|
27
|
+
};
|
|
28
|
+
funds_unlocked_at_last_rate_change: string;
|
|
29
|
+
last_rate_change_time: string;
|
|
30
|
+
last_withdrawn_at: string;
|
|
31
|
+
meta: {
|
|
32
|
+
automatic_withdrawal: boolean;
|
|
33
|
+
can_topup: boolean;
|
|
34
|
+
can_update_rate: boolean;
|
|
35
|
+
cancelable_by_recipient: boolean;
|
|
36
|
+
cancelable_by_sender: boolean;
|
|
37
|
+
contract_name: string;
|
|
38
|
+
pausable: boolean;
|
|
39
|
+
transferable_by_recipient: boolean;
|
|
40
|
+
transferable_by_sender: boolean;
|
|
41
|
+
withdrawal_frequency: string;
|
|
42
|
+
};
|
|
43
|
+
pause_cumulative: string;
|
|
44
|
+
period: string;
|
|
45
|
+
recipient: string;
|
|
46
|
+
sender: string;
|
|
47
|
+
start: string;
|
|
48
|
+
withdrawn: string;
|
|
49
|
+
}
|
|
50
|
+
export declare class Contract implements Stream {
|
|
51
|
+
magic: number;
|
|
52
|
+
version: number;
|
|
53
|
+
createdAt: number;
|
|
54
|
+
withdrawnAmount: BN;
|
|
55
|
+
canceledAt: number;
|
|
56
|
+
end: number;
|
|
57
|
+
lastWithdrawnAt: number;
|
|
58
|
+
sender: string;
|
|
59
|
+
senderTokens: string;
|
|
60
|
+
recipient: string;
|
|
61
|
+
recipientTokens: string;
|
|
62
|
+
mint: string;
|
|
63
|
+
escrowTokens: string;
|
|
64
|
+
streamflowTreasury: string;
|
|
65
|
+
streamflowTreasuryTokens: string;
|
|
66
|
+
streamflowFeeTotal: BN;
|
|
67
|
+
streamflowFeeWithdrawn: BN;
|
|
68
|
+
streamflowFeePercent: number;
|
|
69
|
+
partnerFeeTotal: BN;
|
|
70
|
+
partnerFeeWithdrawn: BN;
|
|
71
|
+
partnerFeePercent: number;
|
|
72
|
+
partner: string;
|
|
73
|
+
partnerTokens: string;
|
|
74
|
+
start: number;
|
|
75
|
+
depositedAmount: BN;
|
|
76
|
+
period: number;
|
|
77
|
+
amountPerPeriod: BN;
|
|
78
|
+
cliff: number;
|
|
79
|
+
cliffAmount: BN;
|
|
80
|
+
cancelableBySender: boolean;
|
|
81
|
+
cancelableByRecipient: boolean;
|
|
82
|
+
automaticWithdrawal: boolean;
|
|
83
|
+
transferableBySender: boolean;
|
|
84
|
+
transferableByRecipient: boolean;
|
|
85
|
+
canTopup: boolean;
|
|
86
|
+
name: string;
|
|
87
|
+
withdrawalFrequency: number;
|
|
88
|
+
closed: boolean;
|
|
89
|
+
currentPauseStart: number;
|
|
90
|
+
pauseCumulative: BN;
|
|
91
|
+
lastRateChangeTime: number;
|
|
92
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
93
|
+
type: StreamType;
|
|
94
|
+
constructor(stream: StreamResource, tokenId: string);
|
|
95
|
+
unlocked(currentTimestamp: number): BN;
|
|
96
|
+
remaining(decimals: number): number;
|
|
97
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Contract = void 0;
|
|
18
|
+
var bn_js_1 = __importDefault(require("bn.js"));
|
|
19
|
+
var contractUtils_1 = require("../common/contractUtils");
|
|
20
|
+
var utils_1 = require("../common/utils");
|
|
21
|
+
var Contract = /** @class */ (function () {
|
|
22
|
+
function Contract(stream, tokenId) {
|
|
23
|
+
this.magic = 0;
|
|
24
|
+
this.version = 0;
|
|
25
|
+
this.createdAt = parseInt(stream.created);
|
|
26
|
+
this.withdrawnAmount = new bn_js_1.default(stream.withdrawn);
|
|
27
|
+
this.canceledAt = parseInt(stream.canceled_at);
|
|
28
|
+
this.end = parseInt(stream.end);
|
|
29
|
+
this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
|
|
30
|
+
this.sender = stream.sender;
|
|
31
|
+
this.senderTokens = stream.sender;
|
|
32
|
+
this.recipient = stream.recipient;
|
|
33
|
+
this.recipientTokens = stream.recipient;
|
|
34
|
+
this.mint = tokenId;
|
|
35
|
+
this.escrowTokens = "";
|
|
36
|
+
this.streamflowTreasury = "";
|
|
37
|
+
this.streamflowTreasuryTokens = "";
|
|
38
|
+
this.streamflowFeeTotal = new bn_js_1.default(0);
|
|
39
|
+
this.streamflowFeeWithdrawn = new bn_js_1.default(0);
|
|
40
|
+
this.streamflowFeePercent = parseInt(stream.fees.streamflow_fee_percentage) / 10000;
|
|
41
|
+
this.partnerFeeTotal = new bn_js_1.default(0);
|
|
42
|
+
this.partnerFeeWithdrawn = new bn_js_1.default(0);
|
|
43
|
+
this.partnerFeePercent = 0;
|
|
44
|
+
this.partner = "";
|
|
45
|
+
this.partnerTokens = "";
|
|
46
|
+
this.start = parseInt(stream.start);
|
|
47
|
+
this.depositedAmount = new bn_js_1.default(stream.amount);
|
|
48
|
+
this.period = parseInt(stream.period);
|
|
49
|
+
this.amountPerPeriod = new bn_js_1.default(stream.amount_per_period);
|
|
50
|
+
this.cliff = parseInt(stream.start);
|
|
51
|
+
this.cliffAmount = new bn_js_1.default(stream.cliff_amount);
|
|
52
|
+
this.cancelableBySender = stream.meta.cancelable_by_sender;
|
|
53
|
+
this.cancelableByRecipient = stream.meta.cancelable_by_recipient;
|
|
54
|
+
this.automaticWithdrawal = stream.meta.automatic_withdrawal;
|
|
55
|
+
this.transferableBySender = stream.meta.transferable_by_sender;
|
|
56
|
+
this.transferableByRecipient = stream.meta.transferable_by_recipient;
|
|
57
|
+
this.canTopup = stream.meta.can_topup;
|
|
58
|
+
var name = stream.meta.contract_name.replace("0x", "");
|
|
59
|
+
this.name = Buffer.from(name, "hex").toString("utf8");
|
|
60
|
+
this.withdrawalFrequency = parseInt(stream.meta.withdrawal_frequency);
|
|
61
|
+
this.closed = stream.closed;
|
|
62
|
+
this.currentPauseStart = parseInt(stream.current_pause_start);
|
|
63
|
+
this.pauseCumulative = new bn_js_1.default(stream.pause_cumulative);
|
|
64
|
+
this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
|
|
65
|
+
this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change);
|
|
66
|
+
this.type = (0, contractUtils_1.buildStreamType)(this);
|
|
67
|
+
}
|
|
68
|
+
Contract.prototype.unlocked = function (currentTimestamp) {
|
|
69
|
+
return (0, contractUtils_1.calculateUnlockedAmount)(__assign(__assign({}, this), { currentTimestamp: currentTimestamp }));
|
|
70
|
+
};
|
|
71
|
+
Contract.prototype.remaining = function (decimals) {
|
|
72
|
+
return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
73
|
+
};
|
|
74
|
+
return Contract;
|
|
75
|
+
}());
|
|
76
|
+
exports.Contract = Contract;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extractAptosErrorCode(errorText: string): string | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractAptosErrorCode = void 0;
|
|
4
|
+
var constants_1 = require("./constants");
|
|
5
|
+
function extractAptosErrorCode(errorText) {
|
|
6
|
+
var match = constants_1.APTOS_ERROR_MATCH_REGEX.exec(errorText);
|
|
7
|
+
if (!match) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return match[2];
|
|
11
|
+
}
|
|
12
|
+
exports.extractAptosErrorCode = extractAptosErrorCode;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AptosAccount, AptosClient, Types, MaybeHexString } from "aptos";
|
|
2
|
+
import { WalletContextState } from "@manahippo/aptos-wallet-adapter";
|
|
3
|
+
export declare class AptosWalletWrapper<T extends WalletContextState | AptosAccount> {
|
|
4
|
+
wallet: T;
|
|
5
|
+
address: MaybeHexString;
|
|
6
|
+
client: AptosClient;
|
|
7
|
+
constructor(wallet: T, client: AptosClient);
|
|
8
|
+
signAndSubmitTransaction(input: Types.TransactionPayload_EntryFunctionPayload): Promise<string>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.AptosWalletWrapper = void 0;
|
|
40
|
+
var aptos_1 = require("aptos");
|
|
41
|
+
var AptosWalletWrapper = /** @class */ (function () {
|
|
42
|
+
function AptosWalletWrapper(wallet, client) {
|
|
43
|
+
this.client = client;
|
|
44
|
+
this.wallet = wallet;
|
|
45
|
+
if (wallet instanceof aptos_1.AptosAccount) {
|
|
46
|
+
this.address = wallet.address();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.address = wallet.account.address;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
AptosWalletWrapper.prototype.signAndSubmitTransaction = function (input) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
54
|
+
var builder, rawTxn, res, signedTx, tx;
|
|
55
|
+
return __generator(this, function (_a) {
|
|
56
|
+
switch (_a.label) {
|
|
57
|
+
case 0:
|
|
58
|
+
if (!(this.wallet instanceof aptos_1.AptosAccount)) return [3 /*break*/, 6];
|
|
59
|
+
builder = new aptos_1.TransactionBuilderRemoteABI(this.client, {
|
|
60
|
+
sender: this.address,
|
|
61
|
+
});
|
|
62
|
+
return [4 /*yield*/, builder.build(input.function, input.type_arguments, input.arguments)];
|
|
63
|
+
case 1:
|
|
64
|
+
rawTxn = _a.sent();
|
|
65
|
+
return [4 /*yield*/, this.client.simulateTransaction(this.wallet, rawTxn)];
|
|
66
|
+
case 2:
|
|
67
|
+
res = _a.sent();
|
|
68
|
+
if (!res[0].success) {
|
|
69
|
+
throw new Error("Transaction Simulation failed: ".concat(JSON.stringify(res)));
|
|
70
|
+
}
|
|
71
|
+
return [4 /*yield*/, this.client.signTransaction(this.wallet, rawTxn)];
|
|
72
|
+
case 3:
|
|
73
|
+
signedTx = _a.sent();
|
|
74
|
+
return [4 /*yield*/, this.client.submitSignedBCSTransaction(signedTx)];
|
|
75
|
+
case 4:
|
|
76
|
+
tx = _a.sent();
|
|
77
|
+
return [4 /*yield*/, this.client.waitForTransaction(tx.hash)];
|
|
78
|
+
case 5:
|
|
79
|
+
_a.sent();
|
|
80
|
+
return [2 /*return*/, tx.hash];
|
|
81
|
+
case 6: return [4 /*yield*/, this.wallet.signAndSubmitTransaction(input)];
|
|
82
|
+
case 7: return [2 /*return*/, (_a.sent()).hash];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
return AptosWalletWrapper;
|
|
88
|
+
}());
|
|
89
|
+
exports.AptosWalletWrapper = AptosWalletWrapper;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData, IUpdateData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData, Stream } from "./types";
|
|
2
|
+
export declare abstract class BaseStreamClient {
|
|
3
|
+
protected abstract create(streamData: ICreateStreamData, chainSpecificParams: any): Promise<ICreateResult>;
|
|
4
|
+
protected abstract createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: any): Promise<IMultiTransactionResult>;
|
|
5
|
+
protected abstract withdraw(withdrawData: IWithdrawData, chainSpecificParams: any): Promise<ITransactionResult>;
|
|
6
|
+
protected abstract cancel(cancelData: ICancelData, chainSpecificParams: any): Promise<ITransactionResult>;
|
|
7
|
+
protected abstract transfer(transferData: ITransferData, chainSpecificParams: any): Promise<ITransactionResult>;
|
|
8
|
+
protected abstract topup(topupData: ITopUpData, chainSpecificParams: any): Promise<ITransactionResult>;
|
|
9
|
+
protected abstract getOne(getOneData: IGetOneData, chainSpecificParams: any): Promise<Stream>;
|
|
10
|
+
protected abstract get(getAllData: IGetAllData, chainSpecificParams: any): Promise<[string, Stream][]>;
|
|
11
|
+
protected abstract update(updateData: IUpdateData, chainSpecificParams: any): Promise<ITransactionResult>;
|
|
12
|
+
extractErrorCode(err: Error): string | null;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseStreamClient = void 0;
|
|
4
|
+
var BaseStreamClient = /** @class */ (function () {
|
|
5
|
+
function BaseStreamClient() {
|
|
6
|
+
}
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
|
+
BaseStreamClient.prototype.extractErrorCode = function (err) {
|
|
9
|
+
return null;
|
|
10
|
+
};
|
|
11
|
+
return BaseStreamClient;
|
|
12
|
+
}());
|
|
13
|
+
exports.BaseStreamClient = BaseStreamClient;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Commitment, ConnectionConfig } from "@solana/web3.js";
|
|
2
|
+
import { Signer } from "ethers";
|
|
3
|
+
import { BaseStreamClient } from "./BaseStreamClient";
|
|
4
|
+
import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData, Stream } from "./types";
|
|
5
|
+
import { AptosStreamClient, ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos";
|
|
6
|
+
import { EvmStreamClient } from "../evm";
|
|
7
|
+
import { SolanaStreamClient, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "../solana";
|
|
8
|
+
import { ICreateStreamSuiExt, ITransactionSuiExt, ISuiIdParameters, SuiStreamClient } from "../sui";
|
|
9
|
+
export interface SolanaStreamClientOptions {
|
|
10
|
+
chain: IChain.Solana;
|
|
11
|
+
clusterUrl: string;
|
|
12
|
+
cluster?: ICluster;
|
|
13
|
+
programId?: string;
|
|
14
|
+
commitment?: Commitment | ConnectionConfig;
|
|
15
|
+
}
|
|
16
|
+
export interface AptosStreamClientOptions {
|
|
17
|
+
chain: IChain.Aptos;
|
|
18
|
+
clusterUrl: string;
|
|
19
|
+
cluster?: ICluster;
|
|
20
|
+
programId?: string;
|
|
21
|
+
maxGas?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface EvmStreamClientOptions {
|
|
24
|
+
chain: IChain.Ethereum | IChain.BNB | IChain.Polygon;
|
|
25
|
+
clusterUrl: string;
|
|
26
|
+
signer: Signer;
|
|
27
|
+
cluster?: ICluster;
|
|
28
|
+
programId?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface SuiStreamClientOptions {
|
|
31
|
+
chain: IChain.Sui;
|
|
32
|
+
clusterUrl: string;
|
|
33
|
+
cluster?: ICluster;
|
|
34
|
+
ids?: ISuiIdParameters;
|
|
35
|
+
}
|
|
36
|
+
/** Type referencing options for specific Chain Client */
|
|
37
|
+
declare type StreamClientOptions<T extends IChain> = T extends IChain.Solana ? SolanaStreamClientOptions : T extends IChain.Aptos ? AptosStreamClientOptions : T extends IChain.Sui ? SuiStreamClientOptions : EvmStreamClientOptions;
|
|
38
|
+
/** Type referencing Chain Client implementation */
|
|
39
|
+
declare type StreamClientType<T extends IChain> = T extends IChain.Solana ? SolanaStreamClient : T extends IChain.Aptos ? AptosStreamClient : T extends IChain.Sui ? SuiStreamClient : EvmStreamClient;
|
|
40
|
+
/** Type referencing additional parameters used by a Chain Client */
|
|
41
|
+
declare type ChainSpecificParams<T, SolanaExt, AptosExt, SuiExt> = T extends SolanaStreamClient ? SolanaExt : T extends AptosStreamClient ? AptosExt : T extends SuiStreamClient ? SuiExt : undefined;
|
|
42
|
+
/** Type referencing additional parameters used on Create by a Chain Client */
|
|
43
|
+
declare type CreateSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, ICreateStreamSolanaExt, ICreateStreamAptosExt, ICreateStreamSuiExt>;
|
|
44
|
+
/** Type referencing additional parameters used on Topup by a Chain Client */
|
|
45
|
+
declare type TopupSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, ITopUpStreamSolanaExt, ITransactionAptosExt, ITransactionSuiExt>;
|
|
46
|
+
/** Type referencing additional parameters used on other interactions by a Chain Client */
|
|
47
|
+
declare type InteractSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, IInteractStreamSolanaExt, ITransactionAptosExt, ITransactionSuiExt>;
|
|
48
|
+
/** Generic Stream Client implementation that wrap Chain Client methods and enriches error messages if possible
|
|
49
|
+
* @property {StreamClientType} - Chain Client implementation
|
|
50
|
+
* @property {chain} - Chain
|
|
51
|
+
*/
|
|
52
|
+
export default class GenericStreamClient<T extends IChain> extends BaseStreamClient {
|
|
53
|
+
nativeStreamClient: StreamClientType<T>;
|
|
54
|
+
chain: IChain;
|
|
55
|
+
constructor(options: StreamClientOptions<T>);
|
|
56
|
+
/**
|
|
57
|
+
* Creates a new stream/vesting contract.
|
|
58
|
+
*/
|
|
59
|
+
create(streamData: ICreateStreamData, chainSpecificParams?: CreateSpecificParams<T>): Promise<ICreateResult>;
|
|
60
|
+
/**
|
|
61
|
+
* Creates multiple stream/vesting contracts.
|
|
62
|
+
*/
|
|
63
|
+
createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams?: CreateSpecificParams<T>): Promise<IMultiTransactionResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Attempts withdrawing from the specified stream.
|
|
66
|
+
*/
|
|
67
|
+
withdraw(withdrawData: IWithdrawData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
|
|
68
|
+
/**
|
|
69
|
+
* Attempts canceling the specified stream.
|
|
70
|
+
*/
|
|
71
|
+
cancel(cancelData: ICancelData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
|
|
72
|
+
/**
|
|
73
|
+
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
74
|
+
*/
|
|
75
|
+
transfer(transferData: ITransferData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
|
|
76
|
+
/**
|
|
77
|
+
* Tops up stream account with specified amount.
|
|
78
|
+
*/
|
|
79
|
+
topup(topupData: ITopUpData, chainSpecificParams?: TopupSpecificParams<T>): Promise<ITransactionResult>;
|
|
80
|
+
/**
|
|
81
|
+
* Fetch stream data by its id (address).
|
|
82
|
+
*/
|
|
83
|
+
getOne(getOneData: IGetOneData): Promise<Stream>;
|
|
84
|
+
/**
|
|
85
|
+
* Fetch streams by sender or recipient address.
|
|
86
|
+
*/
|
|
87
|
+
get(getAllData: IGetAllData): Promise<[string, Stream][]>;
|
|
88
|
+
/**
|
|
89
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
90
|
+
*/
|
|
91
|
+
update(updateData: IUpdateData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
|
|
92
|
+
}
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
var BaseStreamClient_1 = require("./BaseStreamClient");
|
|
19
|
+
var types_1 = require("./types");
|
|
20
|
+
var utils_1 = require("./utils");
|
|
21
|
+
var aptos_1 = require("../aptos");
|
|
22
|
+
var evm_1 = require("../evm");
|
|
23
|
+
var solana_1 = require("../solana");
|
|
24
|
+
var sui_1 = require("../sui");
|
|
25
|
+
/** Generic Stream Client implementation that wrap Chain Client methods and enriches error messages if possible
|
|
26
|
+
* @property {StreamClientType} - Chain Client implementation
|
|
27
|
+
* @property {chain} - Chain
|
|
28
|
+
*/
|
|
29
|
+
var GenericStreamClient = /** @class */ (function (_super) {
|
|
30
|
+
__extends(GenericStreamClient, _super);
|
|
31
|
+
function GenericStreamClient(options) {
|
|
32
|
+
var _this = _super.call(this) || this;
|
|
33
|
+
_this.chain = options.chain;
|
|
34
|
+
switch (options.chain) {
|
|
35
|
+
case types_1.IChain.Solana:
|
|
36
|
+
_this.nativeStreamClient = new solana_1.SolanaStreamClient(options.clusterUrl, options.cluster, options.commitment, options.programId);
|
|
37
|
+
break;
|
|
38
|
+
case types_1.IChain.Aptos:
|
|
39
|
+
_this.nativeStreamClient = new aptos_1.AptosStreamClient(options.clusterUrl, options.cluster, options.maxGas, options.programId);
|
|
40
|
+
break;
|
|
41
|
+
case types_1.IChain.BNB:
|
|
42
|
+
case types_1.IChain.Ethereum:
|
|
43
|
+
case types_1.IChain.Polygon:
|
|
44
|
+
_this.nativeStreamClient = new evm_1.EvmStreamClient(options.clusterUrl, options.chain, options.signer, options.cluster, options.programId);
|
|
45
|
+
break;
|
|
46
|
+
case types_1.IChain.Sui:
|
|
47
|
+
_this.nativeStreamClient = new sui_1.SuiStreamClient(options.clusterUrl, options.cluster, options.ids);
|
|
48
|
+
}
|
|
49
|
+
return _this;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new stream/vesting contract.
|
|
53
|
+
*/
|
|
54
|
+
GenericStreamClient.prototype.create = function (streamData, chainSpecificParams) {
|
|
55
|
+
var _this = this;
|
|
56
|
+
return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.create(streamData, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Creates multiple stream/vesting contracts.
|
|
60
|
+
*/
|
|
61
|
+
GenericStreamClient.prototype.createMultiple = function (multipleStreamData, chainSpecificParams) {
|
|
62
|
+
var _this = this;
|
|
63
|
+
return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.createMultiple(multipleStreamData, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Attempts withdrawing from the specified stream.
|
|
67
|
+
*/
|
|
68
|
+
GenericStreamClient.prototype.withdraw = function (withdrawData, chainSpecificParams) {
|
|
69
|
+
var _this = this;
|
|
70
|
+
return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.withdraw(withdrawData, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Attempts canceling the specified stream.
|
|
74
|
+
*/
|
|
75
|
+
GenericStreamClient.prototype.cancel = function (cancelData, chainSpecificParams) {
|
|
76
|
+
var _this = this;
|
|
77
|
+
return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.cancel(cancelData, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
81
|
+
*/
|
|
82
|
+
GenericStreamClient.prototype.transfer = function (transferData, chainSpecificParams) {
|
|
83
|
+
var _this = this;
|
|
84
|
+
return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.transfer(transferData, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Tops up stream account with specified amount.
|
|
88
|
+
*/
|
|
89
|
+
GenericStreamClient.prototype.topup = function (topupData, chainSpecificParams) {
|
|
90
|
+
var _this = this;
|
|
91
|
+
return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.topup(topupData, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Fetch stream data by its id (address).
|
|
95
|
+
*/
|
|
96
|
+
GenericStreamClient.prototype.getOne = function (getOneData) {
|
|
97
|
+
return this.nativeStreamClient.getOne(getOneData);
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Fetch streams by sender or recipient address.
|
|
101
|
+
*/
|
|
102
|
+
GenericStreamClient.prototype.get = function (getAllData) {
|
|
103
|
+
return this.nativeStreamClient.get(getAllData);
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
107
|
+
*/
|
|
108
|
+
GenericStreamClient.prototype.update = function (updateData, chainSpecificParams) {
|
|
109
|
+
var _this = this;
|
|
110
|
+
return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.update(updateData, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
|
|
111
|
+
};
|
|
112
|
+
return GenericStreamClient;
|
|
113
|
+
}(BaseStreamClient_1.BaseStreamClient));
|
|
114
|
+
exports.default = GenericStreamClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const BASE_FEE = 1002500;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import BN from "bn.js";
|
|
2
|
+
import { StreamType } from "./types";
|
|
3
|
+
interface ICalculateUnlockedAmount {
|
|
4
|
+
depositedAmount: BN;
|
|
5
|
+
cliff: number;
|
|
6
|
+
cliffAmount: BN;
|
|
7
|
+
end: number;
|
|
8
|
+
currentTimestamp: number;
|
|
9
|
+
lastRateChangeTime: number;
|
|
10
|
+
period: number;
|
|
11
|
+
amountPerPeriod: BN;
|
|
12
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
13
|
+
}
|
|
14
|
+
export declare const calculateUnlockedAmount: ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }: ICalculateUnlockedAmount) => BN;
|
|
15
|
+
export declare const isCliffCloseToDepositedAmount: (streamData: {
|
|
16
|
+
depositedAmount: BN;
|
|
17
|
+
cliffAmount: BN;
|
|
18
|
+
}) => boolean;
|
|
19
|
+
export declare const isPayment: (streamData: {
|
|
20
|
+
canTopup: boolean;
|
|
21
|
+
}) => boolean;
|
|
22
|
+
export declare const isVesting: (streamData: {
|
|
23
|
+
canTopup: boolean;
|
|
24
|
+
depositedAmount: BN;
|
|
25
|
+
cliffAmount: BN;
|
|
26
|
+
}) => boolean;
|
|
27
|
+
export declare const isTokenLock: (streamData: {
|
|
28
|
+
canTopup: boolean;
|
|
29
|
+
automaticWithdrawal: boolean;
|
|
30
|
+
cancelableBySender: boolean;
|
|
31
|
+
cancelableByRecipient: boolean;
|
|
32
|
+
transferableBySender: boolean;
|
|
33
|
+
transferableByRecipient: boolean;
|
|
34
|
+
depositedAmount: BN;
|
|
35
|
+
cliffAmount: BN;
|
|
36
|
+
}) => boolean;
|
|
37
|
+
export declare const buildStreamType: (streamData: {
|
|
38
|
+
canTopup: boolean;
|
|
39
|
+
automaticWithdrawal: boolean;
|
|
40
|
+
cancelableBySender: boolean;
|
|
41
|
+
cancelableByRecipient: boolean;
|
|
42
|
+
transferableBySender: boolean;
|
|
43
|
+
transferableByRecipient: boolean;
|
|
44
|
+
depositedAmount: BN;
|
|
45
|
+
cliffAmount: BN;
|
|
46
|
+
}) => StreamType;
|
|
47
|
+
export {};
|