@streamflow/stream 13.4.0 → 13.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{index-BqHEM38f.d.cts → index-BLL6w66C.d.cts} +10 -1
- package/dist/cjs/index.cjs +89 -25
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/solana/api/index.cjs +88 -25
- package/dist/cjs/solana/api/index.cjs.map +1 -1
- package/dist/cjs/solana/api/index.d.cts +1 -1
- package/dist/cjs/solana/index.cjs +89 -25
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +10 -3
- package/dist/esm/{index-CYAitoQO.d.ts → index-FDwxtRYV.d.ts} +10 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +90 -27
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/api/index.d.ts +1 -1
- package/dist/esm/solana/api/index.js +89 -26
- package/dist/esm/solana/api/index.js.map +1 -1
- package/dist/esm/solana/index.d.ts +10 -3
- package/dist/esm/solana/index.js +90 -27
- package/dist/esm/solana/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { l as BatchCreationItem, m as BatchExecuteResult, n as BatchInstructionResult, q as BuildTransactionFn, r as BuildTransactionOptions, s as BuiltTransaction, C as CancelFn, x as CreateBatchFn, y as CreateFn, z as CreateInstructionResult, G as Env, H as ExecuteBatchFn, J as ExecuteBatchSequentialFn, K as ExecuteFn, L as ExecutionEnv, T as ICreateLockBatchParams, U as ICreateLockParams, a0 as ICreateVestingBatchParams, a1 as ICreateVestingParams, a8 as ILockBatchRecipient, aj as IVestingBatchRecipient, am as InstructionResult, an as Invoker, aq as NativeOptions, at as SignFn, az as TopupFn, aB as TransferFn, aC as UpdateFn, aE as WithdrawFn, aF as buildLockBatchParams, aG as buildLockParams, aH as buildTransaction, aI as buildVestingBatchParams, aJ as buildVestingParams, aK as cancel, aL as computeAmountPerPeriod, aM as create, aN as createBatch, aO as createClientFromEnv, aP as createLock, aQ as createLockBatch, aR as createVesting, aS as createVestingBatch, aT as execute, aU as executeBatch, aV as executeBatchSequential, aW as resolveConnection, aX as resolveDuration, aY as sign, aZ as topup, a_ as transfer, a$ as update, b0 as withdraw } from '../../index-BLL6w66C.cjs';
|
|
2
2
|
import '@solana/wallet-adapter-base';
|
|
3
3
|
import '@solana/web3.js';
|
|
4
4
|
import '@streamflow/common';
|
|
@@ -87,6 +87,24 @@ var isTokenLock = (streamData) => {
|
|
|
87
87
|
}
|
|
88
88
|
return false;
|
|
89
89
|
};
|
|
90
|
+
var isStrictTokenLockCreate = (data, now = Math.floor(Date.now() / 1e3)) => {
|
|
91
|
+
if (data.canTopup || data.automaticWithdrawal || data.cancelableBySender || data.cancelableByRecipient || data.transferableBySender) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
if (!isCliffCloseToDepositedAmount({ depositedAmount: data.amount, cliffAmount: data.cliffAmount })) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
if (data.cliffAmount.gt(data.amount) || data.amountPerPeriod.isZero()) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const remaining = data.amount.sub(data.cliffAmount);
|
|
101
|
+
const periodsLeft = remaining.add(data.amountPerPeriod).subn(1).div(data.amountPerPeriod);
|
|
102
|
+
const cliff = data.start === 0 ? now : data.cliff;
|
|
103
|
+
const unlockStart = cliff > 0 ? cliff : data.start;
|
|
104
|
+
const end = new BN3__default.default(unlockStart).add(periodsLeft.mul(new BN3__default.default(data.period)));
|
|
105
|
+
const cliffEndGap = end.sub(new BN3__default.default(cliff));
|
|
106
|
+
return !cliffEndGap.isNeg() && cliffEndGap.lten(MAX_CLIFF_END_GAP_SECONDS);
|
|
107
|
+
};
|
|
90
108
|
var buildStreamType = (streamData) => {
|
|
91
109
|
if (isTokenLock(streamData)) {
|
|
92
110
|
return "lock" /* Lock */;
|
|
@@ -3365,6 +3383,27 @@ var transformContract = async (schema) => {
|
|
|
3365
3383
|
// solana/StreamClient.ts
|
|
3366
3384
|
var METADATA_ACC_SIZE = 1104;
|
|
3367
3385
|
var ALIGNED_METADATA_ACC_SIZE = 320;
|
|
3386
|
+
var PARTNER_LINK_DISCRIMINATOR = buffer.Buffer.from([114, 220, 250, 94, 181, 182, 195, 222]);
|
|
3387
|
+
var PARTNER_LINK_SIZE = 8 + 32 + 32 + 32;
|
|
3388
|
+
var decodePartnerLink = (data) => data.length >= PARTNER_LINK_SIZE && data.subarray(0, 8).equals(PARTNER_LINK_DISCRIMINATOR) ? { partnerPubkey: new web3_js.PublicKey(data.subarray(8, 40)), linkedPubkey: new web3_js.PublicKey(data.subarray(40, 72)) } : null;
|
|
3389
|
+
var findFees = (partners, address) => {
|
|
3390
|
+
const filteredPartners = partners.filter((partner2) => new web3_js.PublicKey(partner2.pubkey).toString() === address);
|
|
3391
|
+
if (filteredPartners.length === 0) {
|
|
3392
|
+
return null;
|
|
3393
|
+
}
|
|
3394
|
+
if (filteredPartners.length > 1) {
|
|
3395
|
+
throw new Error("More than one partner found, fees fetching is not possible.");
|
|
3396
|
+
}
|
|
3397
|
+
const partner = filteredPartners[0];
|
|
3398
|
+
return {
|
|
3399
|
+
creationFeeSol: Number(partner.creation_fee),
|
|
3400
|
+
autoClaimFeeSol: Number(partner.auto_claim_fee),
|
|
3401
|
+
streamflowFee: Number(partner.token_fee_percent.toFixed(4)),
|
|
3402
|
+
streamflowLockFee: Number(partner.token_lock_token_fee_percent.toFixed(4)),
|
|
3403
|
+
partnerFee: 0
|
|
3404
|
+
};
|
|
3405
|
+
};
|
|
3406
|
+
var getWrapFeePercent = (rates, data) => isStrictTokenLockCreate(data) ? rates.streamflowLockFee : rates.streamflowFee;
|
|
3368
3407
|
var SolanaStreamClient = class {
|
|
3369
3408
|
/**
|
|
3370
3409
|
* Create Stream instance
|
|
@@ -3458,10 +3497,8 @@ var SolanaStreamClient = class {
|
|
|
3458
3497
|
tokenProgramId ? new web3_js.PublicKey(tokenProgramId) : void 0
|
|
3459
3498
|
);
|
|
3460
3499
|
if (isNative) {
|
|
3461
|
-
const
|
|
3462
|
-
|
|
3463
|
-
});
|
|
3464
|
-
const totalAmount = calculateTotalAmountToDeposit(amount, totalFee);
|
|
3500
|
+
const rates = await this.getCreateFeeRates(data.partnerLink, sender.publicKey);
|
|
3501
|
+
const totalAmount = calculateTotalAmountToDeposit(amount, getWrapFeePercent(rates, data));
|
|
3465
3502
|
ixs.push(...await common.prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
|
|
3466
3503
|
}
|
|
3467
3504
|
const {
|
|
@@ -3848,7 +3885,20 @@ var SolanaStreamClient = class {
|
|
|
3848
3885
|
computeLimit
|
|
3849
3886
|
});
|
|
3850
3887
|
if (isNative) {
|
|
3851
|
-
const
|
|
3888
|
+
const rates = await this.getCreateFeeRates(partnerLink, sender.publicKey);
|
|
3889
|
+
const totalFee = getWrapFeePercent(rates, {
|
|
3890
|
+
start,
|
|
3891
|
+
amount: depositedAmount,
|
|
3892
|
+
period,
|
|
3893
|
+
cliff,
|
|
3894
|
+
cliffAmount,
|
|
3895
|
+
amountPerPeriod,
|
|
3896
|
+
canTopup,
|
|
3897
|
+
automaticWithdrawal,
|
|
3898
|
+
cancelableBySender,
|
|
3899
|
+
cancelableByRecipient,
|
|
3900
|
+
transferableBySender
|
|
3901
|
+
});
|
|
3852
3902
|
const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
|
|
3853
3903
|
ixs.push(...await common.prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
|
|
3854
3904
|
}
|
|
@@ -3938,6 +3988,7 @@ var SolanaStreamClient = class {
|
|
|
3938
3988
|
if (recipients.length === 0) {
|
|
3939
3989
|
throw new Error("Recipients array is empty!");
|
|
3940
3990
|
}
|
|
3991
|
+
const wrapFeeRates = isNative ? await this.getCreateFeeRates(data.partnerLink, sender.publicKey) : void 0;
|
|
3941
3992
|
for (let i = 0; i < recipients.length; i++) {
|
|
3942
3993
|
const recipientData = recipients[i];
|
|
3943
3994
|
const createStreamData = { ...streamParams, ...recipientData };
|
|
@@ -3946,8 +3997,8 @@ var SolanaStreamClient = class {
|
|
|
3946
3997
|
metadataPubKeys: metadataPubKeysExt?.[i] ? [metadataPubKeysExt[i]] : void 0
|
|
3947
3998
|
};
|
|
3948
3999
|
const wrapInstructions = [];
|
|
3949
|
-
if (
|
|
3950
|
-
const totalFee =
|
|
4000
|
+
if (wrapFeeRates) {
|
|
4001
|
+
const totalFee = getWrapFeePercent(wrapFeeRates, createStreamData);
|
|
3951
4002
|
const recipientAmount = calculateTotalAmountToDeposit(recipientData.amount, totalFee);
|
|
3952
4003
|
wrapInstructions.push(...await common.prepareWrappedAccount(this.connection, sender.publicKey, recipientAmount));
|
|
3953
4004
|
}
|
|
@@ -4858,26 +4909,38 @@ var SolanaStreamClient = class {
|
|
|
4858
4909
|
* @returns Fees
|
|
4859
4910
|
*/
|
|
4860
4911
|
async getFees({ address }) {
|
|
4912
|
+
const partners = await this.getFeeRows();
|
|
4913
|
+
return partners ? findFees(partners, address) : null;
|
|
4914
|
+
}
|
|
4915
|
+
async getFeeRows() {
|
|
4861
4916
|
const data = await this.connection.getAccountInfo(this.feeOraclePublicKey);
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4917
|
+
return data ? borsh__namespace.deserialize(PARTNERS_SCHEMA, data.data) : null;
|
|
4918
|
+
}
|
|
4919
|
+
/**
|
|
4920
|
+
* Fee rates the program applies to a create from `sender` with `partnerLink`, used to size the WSOL wrap.
|
|
4921
|
+
* Mirrors `resolve_vesting_partner`: a `partnerLink` counts if it signs or the partner oracle owns it, and a
|
|
4922
|
+
* PartnerLink account stands for its partner. A link to another wallet fails the program's lookup, which then
|
|
4923
|
+
* charges its hardcoded fallback and skips the sender's own row. Otherwise the sender's own row, then the
|
|
4924
|
+
* partner's, then the default row. `partner` only takes a share and never picks the row.
|
|
4925
|
+
*/
|
|
4926
|
+
async getCreateFeeRates(partnerLink, sender) {
|
|
4927
|
+
const fallback = { streamflowFee: DEFAULT_STREAMFLOW_FEE, streamflowLockFee: DEFAULT_STREAMFLOW_FEE };
|
|
4928
|
+
let linkedPartner;
|
|
4929
|
+
if (partnerLink?.isSigner) {
|
|
4930
|
+
linkedPartner = common.pk(partnerLink.address).toBase58();
|
|
4931
|
+
} else if (partnerLink) {
|
|
4932
|
+
const address = common.pk(partnerLink.address);
|
|
4933
|
+
const account = await this.connection.getAccountInfo(address);
|
|
4934
|
+
if (account?.owner.equals(this.partnerOracleProgramId)) {
|
|
4935
|
+
const link = decodePartnerLink(account.data);
|
|
4936
|
+
if (link && !link.linkedPubkey.equals(sender)) {
|
|
4937
|
+
return fallback;
|
|
4938
|
+
}
|
|
4939
|
+
linkedPartner = (link?.partnerPubkey ?? address).toBase58();
|
|
4940
|
+
}
|
|
4872
4941
|
}
|
|
4873
|
-
const
|
|
4874
|
-
return
|
|
4875
|
-
creationFeeSol: Number(partner.creation_fee),
|
|
4876
|
-
autoClaimFeeSol: Number(partner.auto_claim_fee),
|
|
4877
|
-
streamflowFee: Number(partner.token_fee_percent.toFixed(4)),
|
|
4878
|
-
streamflowLockFee: Number(partner.token_lock_token_fee_percent.toFixed(4)),
|
|
4879
|
-
partnerFee: 0
|
|
4880
|
-
};
|
|
4942
|
+
const partners = await this.getFeeRows() ?? [];
|
|
4943
|
+
return findFees(partners, sender.toBase58()) ?? (linkedPartner ? findFees(partners, linkedPartner) : null) ?? findFees(partners, WITHDRAWOR) ?? fallback;
|
|
4881
4944
|
}
|
|
4882
4945
|
/**
|
|
4883
4946
|
* Gets default streamflow fee
|
|
@@ -6001,6 +6064,7 @@ exports.isAligned = isAligned;
|
|
|
6001
6064
|
exports.isCliffCloseToDepositedAmount = isCliffCloseToDepositedAmount;
|
|
6002
6065
|
exports.isCreateAlignedStreamData = isCreateAlignedStreamData;
|
|
6003
6066
|
exports.isDynamicLock = isDynamicLock;
|
|
6067
|
+
exports.isStrictTokenLockCreate = isStrictTokenLockCreate;
|
|
6004
6068
|
exports.isTokenLock = isTokenLock;
|
|
6005
6069
|
exports.isVesting = isVesting;
|
|
6006
6070
|
exports.resolveConnection = resolveConnection;
|