@streamflow/stream 11.3.1 → 11.4.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.cjs +205 -77
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/solana/index.cjs +205 -77
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +37 -6
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +207 -79
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/index.d.ts +37 -6
- package/dist/esm/solana/index.js +207 -79
- package/dist/esm/solana/index.js.map +1 -1
- package/package.json +4 -4
package/dist/cjs/index.cjs
CHANGED
|
@@ -723,6 +723,9 @@ var createStreamInstruction = async (data, programId, accounts) => {
|
|
|
723
723
|
},
|
|
724
724
|
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
|
|
725
725
|
];
|
|
726
|
+
if (accounts.partnerLink) {
|
|
727
|
+
keys.push({ pubkey: accounts.partnerLink.pubkey, isSigner: accounts.partnerLink.isSigner, isWritable: false });
|
|
728
|
+
}
|
|
726
729
|
let bufferData = buffer.Buffer.alloc(createStreamLayout.span);
|
|
727
730
|
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
728
731
|
const streamNameBuffer = buffer.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
@@ -773,6 +776,9 @@ var createUncheckedStreamInstruction = async (data, programId, accounts) => {
|
|
|
773
776
|
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
774
777
|
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
|
|
775
778
|
];
|
|
779
|
+
if (accounts.partnerLink) {
|
|
780
|
+
keys.push({ pubkey: accounts.partnerLink.pubkey, isSigner: accounts.partnerLink.isSigner, isWritable: false });
|
|
781
|
+
}
|
|
776
782
|
if (accounts.payer) {
|
|
777
783
|
keys.unshift({
|
|
778
784
|
pubkey: accounts.payer,
|
|
@@ -846,6 +852,9 @@ var createStreamV2Instruction = async (data, programId, accounts) => {
|
|
|
846
852
|
},
|
|
847
853
|
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
|
|
848
854
|
];
|
|
855
|
+
if (accounts.partnerLink) {
|
|
856
|
+
keys.push({ pubkey: accounts.partnerLink.pubkey, isSigner: accounts.partnerLink.isSigner, isWritable: false });
|
|
857
|
+
}
|
|
849
858
|
let bufferData = buffer.Buffer.alloc(createStreamV2Layout.span);
|
|
850
859
|
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
851
860
|
const streamNameBuffer = buffer.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
@@ -897,6 +906,9 @@ var createUncheckedStreamV2Instruction = async (data, programId, accounts) => {
|
|
|
897
906
|
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
898
907
|
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
|
|
899
908
|
];
|
|
909
|
+
if (accounts.partnerLink) {
|
|
910
|
+
keys.push({ pubkey: accounts.partnerLink.pubkey, isSigner: accounts.partnerLink.isSigner, isWritable: false });
|
|
911
|
+
}
|
|
900
912
|
if (accounts.payer) {
|
|
901
913
|
keys.unshift({
|
|
902
914
|
pubkey: accounts.payer,
|
|
@@ -3051,6 +3063,10 @@ var SolanaStreamClient = class {
|
|
|
3051
3063
|
const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams) ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams) : await this.prepareCreateLinearStreamInstructions(streamParams, extParams);
|
|
3052
3064
|
return { ixs, metadata, metadataPubKey };
|
|
3053
3065
|
}
|
|
3066
|
+
/**
|
|
3067
|
+
* Builds instructions for creating an aligned unlock stream.
|
|
3068
|
+
* For Token-2022 mints with a transfer hook, partner link and hook accounts are appended as remaining accounts.
|
|
3069
|
+
*/
|
|
3054
3070
|
async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
|
|
3055
3071
|
const {
|
|
3056
3072
|
tokenId: mint,
|
|
@@ -3063,6 +3079,7 @@ var SolanaStreamClient = class {
|
|
|
3063
3079
|
transferableBySender,
|
|
3064
3080
|
transferableByRecipient,
|
|
3065
3081
|
partner,
|
|
3082
|
+
partnerLink,
|
|
3066
3083
|
recipient,
|
|
3067
3084
|
cliffAmount,
|
|
3068
3085
|
amountPerPeriod,
|
|
@@ -3092,13 +3109,17 @@ var SolanaStreamClient = class {
|
|
|
3092
3109
|
const metadata = !metadataPubKeys ? web3_js.Keypair.generate() : void 0;
|
|
3093
3110
|
const metadataPubKey = metadata ? metadata.publicKey : metadataPubKeys[0];
|
|
3094
3111
|
common.invariant(metadataPubKey, "Metadata public key is required");
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3112
|
+
const { mint: mintAccount, tokenProgramId: detectedTokenProgramId } = await common.getMintAndProgram(
|
|
3113
|
+
this.connection,
|
|
3114
|
+
mintPublicKey
|
|
3115
|
+
);
|
|
3116
|
+
const tokenProgramId = streamTokenProgramId ? new web3_js.PublicKey(streamTokenProgramId) : detectedTokenProgramId;
|
|
3117
|
+
const senderTokens = await common.ata(mintPublicKey, sender.publicKey, tokenProgramId);
|
|
3099
3118
|
const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
|
|
3100
3119
|
const streamflowProgramPublicKey = new web3_js.PublicKey(this.programId);
|
|
3101
3120
|
const escrowPDA = deriveEscrowPDA(streamflowProgramPublicKey, metadataPubKey);
|
|
3121
|
+
const proxyMetadata = deriveContractPDA(this.alignedProxyProgram.programId, metadataPubKey);
|
|
3122
|
+
const proxyTokens = await common.ata(mintPublicKey, proxyMetadata, tokenProgramId);
|
|
3102
3123
|
const oracle = priceOracle ?? deriveTestOraclePDA(this.alignedProxyProgram.programId, mintPublicKey, sender.publicKey);
|
|
3103
3124
|
const ixs = common.prepareBaseInstructions(this.connection, {
|
|
3104
3125
|
computePrice,
|
|
@@ -3111,7 +3132,7 @@ var SolanaStreamClient = class {
|
|
|
3111
3132
|
}
|
|
3112
3133
|
const encodedUIntArray = new TextEncoder().encode(streamName);
|
|
3113
3134
|
const streamNameArray = Array.from(encodedUIntArray);
|
|
3114
|
-
const
|
|
3135
|
+
const createMethod = this.alignedProxyProgram.methods.create({
|
|
3115
3136
|
startTime: new BN3__default.default(start),
|
|
3116
3137
|
netAmountDeposited: depositedAmount,
|
|
3117
3138
|
period: new BN3__default.default(period),
|
|
@@ -3147,7 +3168,18 @@ var SolanaStreamClient = class {
|
|
|
3147
3168
|
priceOracle: oracle,
|
|
3148
3169
|
tokenProgram: tokenProgramId,
|
|
3149
3170
|
streamflowProgram: this.programId
|
|
3150
|
-
})
|
|
3171
|
+
});
|
|
3172
|
+
const remainingAccounts = partnerLink ? [{ pubkey: new web3_js.PublicKey(partnerLink.address), isSigner: partnerLink.isSigner, isWritable: false }] : [];
|
|
3173
|
+
const createIx = await (remainingAccounts.length > 0 ? createMethod.remainingAccounts(remainingAccounts) : createMethod).instruction();
|
|
3174
|
+
await this.addTransferHookAccounts(createIx, {
|
|
3175
|
+
mint: mintPublicKey,
|
|
3176
|
+
mintAccount,
|
|
3177
|
+
tokenProgramId,
|
|
3178
|
+
potentialTransfers: [
|
|
3179
|
+
{ source: senderTokens, destination: proxyTokens, owner: sender.publicKey },
|
|
3180
|
+
{ source: proxyTokens, destination: escrowPDA, owner: proxyMetadata }
|
|
3181
|
+
]
|
|
3182
|
+
});
|
|
3151
3183
|
ixs.push(createIx);
|
|
3152
3184
|
return { ixs, metadata, metadataPubKey };
|
|
3153
3185
|
}
|
|
@@ -3178,6 +3210,7 @@ var SolanaStreamClient = class {
|
|
|
3178
3210
|
automaticWithdrawal = false,
|
|
3179
3211
|
withdrawalFrequency = 0,
|
|
3180
3212
|
partner,
|
|
3213
|
+
partnerLink,
|
|
3181
3214
|
tokenProgramId: streamTokenProgramId,
|
|
3182
3215
|
nonce
|
|
3183
3216
|
}, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
|
|
@@ -3199,10 +3232,11 @@ var SolanaStreamClient = class {
|
|
|
3199
3232
|
[buffer.Buffer.from("strm"), metadataPubKey.toBuffer()],
|
|
3200
3233
|
this.programId
|
|
3201
3234
|
);
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3235
|
+
const { mint: mintAccount, tokenProgramId: detectedTokenProgramId } = await common.getMintAndProgram(
|
|
3236
|
+
this.connection,
|
|
3237
|
+
mintPublicKey
|
|
3238
|
+
);
|
|
3239
|
+
const tokenProgramId = streamTokenProgramId ? new web3_js.PublicKey(streamTokenProgramId) : detectedTokenProgramId;
|
|
3206
3240
|
const senderTokens = await common.ata(mintPublicKey, sender.publicKey, tokenProgramId);
|
|
3207
3241
|
const recipientTokens = await common.ata(mintPublicKey, recipientPublicKey, tokenProgramId);
|
|
3208
3242
|
const streamflowTreasuryTokens = await common.ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
@@ -3226,7 +3260,8 @@ var SolanaStreamClient = class {
|
|
|
3226
3260
|
tokenProgram: tokenProgramId,
|
|
3227
3261
|
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
3228
3262
|
withdrawor: WITHDRAWOR_PUBLIC_KEY,
|
|
3229
|
-
systemProgram: web3_js.SystemProgram.programId
|
|
3263
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
3264
|
+
partnerLink: partnerLink ? { pubkey: new web3_js.PublicKey(partnerLink.address), isSigner: partnerLink.isSigner } : void 0
|
|
3230
3265
|
};
|
|
3231
3266
|
const baseData = {
|
|
3232
3267
|
start: new BN3__default.default(start),
|
|
@@ -3246,11 +3281,14 @@ var SolanaStreamClient = class {
|
|
|
3246
3281
|
name,
|
|
3247
3282
|
withdrawFrequency: new BN3__default.default(automaticWithdrawal ? withdrawalFrequency : period)
|
|
3248
3283
|
};
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3284
|
+
const createIx = nonce != null ? await createStreamV2Instruction({ ...baseData, nonce }, this.programId, accounts) : await createStreamInstruction(baseData, this.programId, accounts);
|
|
3285
|
+
await this.addTransferHookAccounts(createIx, {
|
|
3286
|
+
mint: mintPublicKey,
|
|
3287
|
+
mintAccount,
|
|
3288
|
+
tokenProgramId,
|
|
3289
|
+
potentialTransfers: [{ source: senderTokens, destination: escrowTokens, owner: sender.publicKey }]
|
|
3290
|
+
});
|
|
3291
|
+
ixs.push(createIx);
|
|
3254
3292
|
return { ixs, metadata, metadataPubKey };
|
|
3255
3293
|
}
|
|
3256
3294
|
/**
|
|
@@ -3311,6 +3349,7 @@ var SolanaStreamClient = class {
|
|
|
3311
3349
|
automaticWithdrawal = false,
|
|
3312
3350
|
withdrawalFrequency = 0,
|
|
3313
3351
|
partner,
|
|
3352
|
+
partnerLink,
|
|
3314
3353
|
nonce
|
|
3315
3354
|
}, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
|
|
3316
3355
|
common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -3327,7 +3366,7 @@ var SolanaStreamClient = class {
|
|
|
3327
3366
|
[buffer.Buffer.from("strm"), metadataPubKey.toBuffer()],
|
|
3328
3367
|
this.programId
|
|
3329
3368
|
);
|
|
3330
|
-
const { tokenProgramId } = await common.getMintAndProgram(this.connection, mintPublicKey);
|
|
3369
|
+
const { mint: mintAccount, tokenProgramId } = await common.getMintAndProgram(this.connection, mintPublicKey);
|
|
3331
3370
|
const senderTokens = await common.ata(mintPublicKey, sender.publicKey, tokenProgramId);
|
|
3332
3371
|
const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
|
|
3333
3372
|
const ixs = common.prepareBaseInstructions(this.connection, {
|
|
@@ -3350,7 +3389,8 @@ var SolanaStreamClient = class {
|
|
|
3350
3389
|
timelockProgram: this.programId,
|
|
3351
3390
|
tokenProgram: tokenProgramId,
|
|
3352
3391
|
withdrawor: WITHDRAWOR_PUBLIC_KEY,
|
|
3353
|
-
systemProgram: web3_js.SystemProgram.programId
|
|
3392
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
3393
|
+
partnerLink: partnerLink ? { pubkey: new web3_js.PublicKey(partnerLink.address), isSigner: partnerLink.isSigner } : void 0
|
|
3354
3394
|
};
|
|
3355
3395
|
const baseData = {
|
|
3356
3396
|
start: new BN3__default.default(start),
|
|
@@ -3378,6 +3418,12 @@ var SolanaStreamClient = class {
|
|
|
3378
3418
|
this.programId,
|
|
3379
3419
|
accounts
|
|
3380
3420
|
);
|
|
3421
|
+
await this.addTransferHookAccounts(createInstruction, {
|
|
3422
|
+
mint: mintPublicKey,
|
|
3423
|
+
mintAccount,
|
|
3424
|
+
tokenProgramId,
|
|
3425
|
+
potentialTransfers: [{ source: senderTokens, destination: escrowTokens, owner: sender.publicKey }]
|
|
3426
|
+
});
|
|
3381
3427
|
ixs.push(createInstruction);
|
|
3382
3428
|
} else {
|
|
3383
3429
|
const rentToExempt = await this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE);
|
|
@@ -3389,6 +3435,12 @@ var SolanaStreamClient = class {
|
|
|
3389
3435
|
newAccountPubkey: metadataPubKey
|
|
3390
3436
|
});
|
|
3391
3437
|
const createInstruction = await createUncheckedStreamInstruction(baseData, this.programId, accounts);
|
|
3438
|
+
await this.addTransferHookAccounts(createInstruction, {
|
|
3439
|
+
mint: mintPublicKey,
|
|
3440
|
+
mintAccount,
|
|
3441
|
+
tokenProgramId,
|
|
3442
|
+
potentialTransfers: [{ source: senderTokens, destination: escrowTokens, owner: sender.publicKey }]
|
|
3443
|
+
});
|
|
3392
3444
|
ixs.push(createMetadataInstruction, createInstruction);
|
|
3393
3445
|
}
|
|
3394
3446
|
return { ixs, metadata, metadataPubKey };
|
|
@@ -3670,7 +3722,7 @@ var SolanaStreamClient = class {
|
|
|
3670
3722
|
common.invariant(escrow?.data, "Couldn't get account info");
|
|
3671
3723
|
const data = decodeStream(escrow.data);
|
|
3672
3724
|
const { sender, recipient, mint, streamflowTreasury, partner, recipientTokens, escrowTokens } = data;
|
|
3673
|
-
const { tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
|
|
3725
|
+
const { mint: mintAccount, tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
|
|
3674
3726
|
const streamflowTreasuryTokens = await common.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
3675
3727
|
const partnerTokens = await common.ata(mint, partner, tokenProgramId);
|
|
3676
3728
|
const ataIx = await this.getCreateATAInstructions(
|
|
@@ -3680,22 +3732,30 @@ var SolanaStreamClient = class {
|
|
|
3680
3732
|
checkTokenAccounts,
|
|
3681
3733
|
tokenProgramId
|
|
3682
3734
|
);
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3735
|
+
const withdrawIx = await withdrawStreamInstruction(amount, this.programId, {
|
|
3736
|
+
partner,
|
|
3737
|
+
partnerTokens,
|
|
3738
|
+
mint,
|
|
3739
|
+
streamflowTreasuryTokens,
|
|
3740
|
+
recipientTokens,
|
|
3741
|
+
escrowTokens,
|
|
3742
|
+
authority: invoker.publicKey,
|
|
3743
|
+
recipient: invoker.publicKey,
|
|
3744
|
+
metadata: streamPublicKey,
|
|
3745
|
+
streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
3746
|
+
tokenProgram: tokenProgramId
|
|
3747
|
+
});
|
|
3748
|
+
await this.addTransferHookAccounts(withdrawIx, {
|
|
3749
|
+
mint,
|
|
3750
|
+
mintAccount,
|
|
3751
|
+
tokenProgramId,
|
|
3752
|
+
potentialTransfers: [
|
|
3753
|
+
{ source: escrowTokens, destination: recipientTokens, owner: streamPublicKey },
|
|
3754
|
+
{ source: escrowTokens, destination: streamflowTreasuryTokens, owner: streamPublicKey },
|
|
3755
|
+
{ source: escrowTokens, destination: partnerTokens, owner: streamPublicKey }
|
|
3756
|
+
]
|
|
3757
|
+
});
|
|
3758
|
+
ixs.push(...ataIx, withdrawIx);
|
|
3699
3759
|
return ixs;
|
|
3700
3760
|
}
|
|
3701
3761
|
/**
|
|
@@ -3734,8 +3794,7 @@ var SolanaStreamClient = class {
|
|
|
3734
3794
|
}
|
|
3735
3795
|
const decoded = decodeStream(account.data);
|
|
3736
3796
|
const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender);
|
|
3737
|
-
|
|
3738
|
-
return ixs;
|
|
3797
|
+
return isAlignedUnlock ? this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : this.prepareCancelLinearStream(cancelData, extParams);
|
|
3739
3798
|
}
|
|
3740
3799
|
/**
|
|
3741
3800
|
* Creates Transaction Instructions for cancel
|
|
@@ -3750,7 +3809,13 @@ var SolanaStreamClient = class {
|
|
|
3750
3809
|
common.invariant(escrowAcc?.data, "Couldn't get account info");
|
|
3751
3810
|
const streamData = decodeStream(escrowAcc.data);
|
|
3752
3811
|
const { sender, recipient, mint, streamflowTreasury, partner, escrowTokens } = streamData;
|
|
3753
|
-
const { tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
|
|
3812
|
+
const { mint: mintAccount, tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
|
|
3813
|
+
const senderTokens = await common.ata(mint, sender, tokenProgramId);
|
|
3814
|
+
const recipientTokens = await common.ata(mint, recipient, tokenProgramId);
|
|
3815
|
+
const streamflowTreasuryTokens = await common.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
3816
|
+
const partnerTokens = await common.ata(mint, partner, tokenProgramId);
|
|
3817
|
+
const proxyMetadata = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
|
|
3818
|
+
const proxyTokens = await common.ata(mint, proxyMetadata, tokenProgramId);
|
|
3754
3819
|
const ixs = common.prepareBaseInstructions(this.connection, {
|
|
3755
3820
|
computePrice,
|
|
3756
3821
|
computeLimit: computeLimit ?? ALIGNED_COMPUTE_LIMIT
|
|
@@ -3762,7 +3827,7 @@ var SolanaStreamClient = class {
|
|
|
3762
3827
|
checkTokenAccounts,
|
|
3763
3828
|
tokenProgramId
|
|
3764
3829
|
);
|
|
3765
|
-
const
|
|
3830
|
+
const cancelMethod = this.alignedProxyProgram.methods.cancel().accountsPartial({
|
|
3766
3831
|
mint,
|
|
3767
3832
|
partner,
|
|
3768
3833
|
recipient,
|
|
@@ -3772,7 +3837,20 @@ var SolanaStreamClient = class {
|
|
|
3772
3837
|
streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
3773
3838
|
tokenProgram: tokenProgramId,
|
|
3774
3839
|
streamflowProgram: this.programId
|
|
3775
|
-
})
|
|
3840
|
+
});
|
|
3841
|
+
const cancelIx = await cancelMethod.instruction();
|
|
3842
|
+
await this.addTransferHookAccounts(cancelIx, {
|
|
3843
|
+
mint,
|
|
3844
|
+
mintAccount,
|
|
3845
|
+
tokenProgramId,
|
|
3846
|
+
potentialTransfers: [
|
|
3847
|
+
{ source: escrowTokens, destination: recipientTokens, owner: streamPublicKey },
|
|
3848
|
+
{ source: escrowTokens, destination: streamflowTreasuryTokens, owner: streamPublicKey },
|
|
3849
|
+
{ source: escrowTokens, destination: partnerTokens, owner: streamPublicKey },
|
|
3850
|
+
{ source: escrowTokens, destination: proxyTokens, owner: streamPublicKey },
|
|
3851
|
+
{ source: proxyTokens, destination: senderTokens, owner: proxyMetadata }
|
|
3852
|
+
]
|
|
3853
|
+
});
|
|
3776
3854
|
ixs.push(...ataIx, cancelIx);
|
|
3777
3855
|
return ixs;
|
|
3778
3856
|
}
|
|
@@ -3789,7 +3867,7 @@ var SolanaStreamClient = class {
|
|
|
3789
3867
|
common.invariant(escrowAcc?.data, "Couldn't get account info");
|
|
3790
3868
|
const data = decodeStream(escrowAcc.data);
|
|
3791
3869
|
const { sender, recipient, partner, streamflowTreasury, mint, senderTokens, recipientTokens, escrowTokens } = data;
|
|
3792
|
-
const { tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
|
|
3870
|
+
const { mint: mintAccount, tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
|
|
3793
3871
|
const streamflowTreasuryTokens = await common.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
3794
3872
|
const partnerTokens = await common.ata(mint, partner, tokenProgramId);
|
|
3795
3873
|
const ixs = common.prepareBaseInstructions(this.connection, {
|
|
@@ -3803,24 +3881,33 @@ var SolanaStreamClient = class {
|
|
|
3803
3881
|
checkTokenAccounts,
|
|
3804
3882
|
tokenProgramId
|
|
3805
3883
|
);
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3884
|
+
const cancelIx = await cancelStreamInstruction(this.programId, {
|
|
3885
|
+
sender,
|
|
3886
|
+
senderTokens,
|
|
3887
|
+
recipient,
|
|
3888
|
+
recipientTokens,
|
|
3889
|
+
streamflowTreasuryTokens,
|
|
3890
|
+
partner,
|
|
3891
|
+
partnerTokens,
|
|
3892
|
+
mint,
|
|
3893
|
+
escrowTokens,
|
|
3894
|
+
authority: invoker.publicKey,
|
|
3895
|
+
metadata: streamPublicKey,
|
|
3896
|
+
streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
3897
|
+
tokenProgram: tokenProgramId
|
|
3898
|
+
});
|
|
3899
|
+
await this.addTransferHookAccounts(cancelIx, {
|
|
3900
|
+
mint,
|
|
3901
|
+
mintAccount,
|
|
3902
|
+
tokenProgramId,
|
|
3903
|
+
potentialTransfers: [
|
|
3904
|
+
{ source: escrowTokens, destination: recipientTokens, owner: streamPublicKey },
|
|
3905
|
+
{ source: escrowTokens, destination: streamflowTreasuryTokens, owner: streamPublicKey },
|
|
3906
|
+
{ source: escrowTokens, destination: partnerTokens, owner: streamPublicKey },
|
|
3907
|
+
{ source: escrowTokens, destination: senderTokens, owner: streamPublicKey }
|
|
3908
|
+
]
|
|
3909
|
+
});
|
|
3910
|
+
ixs.push(...ixsAta, cancelIx);
|
|
3824
3911
|
return ixs;
|
|
3825
3912
|
}
|
|
3826
3913
|
/**
|
|
@@ -3923,28 +4010,35 @@ var SolanaStreamClient = class {
|
|
|
3923
4010
|
throw new Error("Couldn't get account info");
|
|
3924
4011
|
}
|
|
3925
4012
|
const { mint, partner, senderTokens, escrowTokens } = decodeStream(escrow?.data);
|
|
3926
|
-
const { tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
|
|
4013
|
+
const { mint: mintAccount, tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
|
|
3927
4014
|
const streamflowTreasuryTokens = await common.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
3928
4015
|
const partnerTokens = await common.ata(mint, partner, tokenProgramId);
|
|
4016
|
+
const totalFee = await this.getTotalFee({ address: partner.toBase58() });
|
|
4017
|
+
const totalAmountToTransfer = calculateTotalAmountToDeposit(amount, totalFee);
|
|
3929
4018
|
if (isNative) {
|
|
3930
|
-
ixs.push(...await common.prepareWrappedAccount(this.connection, invoker.publicKey,
|
|
4019
|
+
ixs.push(...await common.prepareWrappedAccount(this.connection, invoker.publicKey, totalAmountToTransfer));
|
|
3931
4020
|
}
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
4021
|
+
const topupIx = await topupStreamInstruction(amount, this.programId, {
|
|
4022
|
+
sender: invoker.publicKey,
|
|
4023
|
+
senderTokens,
|
|
4024
|
+
metadata: streamPublicKey,
|
|
4025
|
+
escrowTokens,
|
|
4026
|
+
streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
4027
|
+
streamflowTreasuryTokens,
|
|
4028
|
+
partner,
|
|
4029
|
+
partnerTokens,
|
|
4030
|
+
mint,
|
|
4031
|
+
tokenProgram: tokenProgramId,
|
|
4032
|
+
withdrawor: WITHDRAWOR_PUBLIC_KEY,
|
|
4033
|
+
systemProgram: web3_js.SystemProgram.programId
|
|
4034
|
+
});
|
|
4035
|
+
await this.addTransferHookAccounts(topupIx, {
|
|
4036
|
+
mint,
|
|
4037
|
+
mintAccount,
|
|
4038
|
+
tokenProgramId,
|
|
4039
|
+
potentialTransfers: [{ source: senderTokens, destination: escrowTokens, owner: invoker.publicKey }]
|
|
4040
|
+
});
|
|
4041
|
+
ixs.push(topupIx);
|
|
3948
4042
|
return ixs;
|
|
3949
4043
|
}
|
|
3950
4044
|
/**
|
|
@@ -4350,6 +4444,40 @@ var SolanaStreamClient = class {
|
|
|
4350
4444
|
}
|
|
4351
4445
|
return { metadata, metadataPubKey };
|
|
4352
4446
|
}
|
|
4447
|
+
/**
|
|
4448
|
+
* Returns the configured transfer hook program for a Token-2022 mint, if present.
|
|
4449
|
+
*/
|
|
4450
|
+
getTransferHookProgramId(mintAccount, tokenProgramId) {
|
|
4451
|
+
if (!tokenProgramId.equals(splToken.TOKEN_2022_PROGRAM_ID)) {
|
|
4452
|
+
return null;
|
|
4453
|
+
}
|
|
4454
|
+
return splToken.getTransferHook(mintAccount)?.programId ?? null;
|
|
4455
|
+
}
|
|
4456
|
+
/**
|
|
4457
|
+
* Appends transfer-hook extra metas for each potential token transfer performed by the instruction.
|
|
4458
|
+
*
|
|
4459
|
+
* Transfer hook may rely on additional accounts/PDAs - derivation path is configured on the transfer hook metadata account, so for each potential transfer we need to check whether these accounts are needed and add them.
|
|
4460
|
+
*/
|
|
4461
|
+
async addTransferHookAccounts(instruction, params) {
|
|
4462
|
+
const { mint, mintAccount, tokenProgramId, potentialTransfers } = params;
|
|
4463
|
+
const transferHookProgramId = this.getTransferHookProgramId(mintAccount, tokenProgramId);
|
|
4464
|
+
if (!transferHookProgramId) {
|
|
4465
|
+
return;
|
|
4466
|
+
}
|
|
4467
|
+
for (const transfer of potentialTransfers) {
|
|
4468
|
+
await splToken.addExtraAccountMetasForExecute(
|
|
4469
|
+
this.connection,
|
|
4470
|
+
instruction,
|
|
4471
|
+
transferHookProgramId,
|
|
4472
|
+
transfer.source,
|
|
4473
|
+
mint,
|
|
4474
|
+
transfer.destination,
|
|
4475
|
+
transfer.owner,
|
|
4476
|
+
1n,
|
|
4477
|
+
this.getCommitment()
|
|
4478
|
+
);
|
|
4479
|
+
}
|
|
4480
|
+
}
|
|
4353
4481
|
/**
|
|
4354
4482
|
* Returns insrtuctions for creating associated token accounts for the provided owners
|
|
4355
4483
|
*/
|