Endpoints
The create stream endpoint requires the sender to transfer the streamed token to the CoinDrip smart contract. If the transaction is successful, the stream is registered on the blockchain. As soon as the start time is reached, the CoinDrip protocol will unlock tokens for the recipient.
#[payable("*")]
#[endpoint(createStream)]
fn create_stream(
&self,
recipient: ManagedAddress,
start_time: u64,
end_time: u64,
can_cancel: OptionalValue<bool>
)
You must also send the token you want to stream in the create stream transaction.
The start_time must be bigger than
self.blockchain().get_block_timestamp(),
or the transaction will fail.TransactionPayload.contractCall()
.setFunction(new ContractFunction("ESDTTransfer"))
.addArg(new BytesValue(Buffer.from('USDC-a2sd58', "utf-8"))) // streamed token identifier
.addArg(new BigUIntValue(TokenPayment.egldFromAmount('100').valueOf())) // streamed token amount
.addArg(new BytesValue(Buffer.from("createStream", "utf-8")))
.addArg(new AddressValue(new Address('erd1aaaa.....'))) // recipient address
.addArg(new U64Value(1674158572)) // start time
.addArg(new U64Value(1674159572)) // end time
.build();
This endpoint transfers the amount of already streamed tokens from the CoinDrip smart contract to the recipient's wallet.
#[endpoint(claimFromStream)]
fn claim_from_stream(
&self,
stream_id: u64
)
The recipient of the stream can only call this endpoint after the present time went over the start time of the stream.
TransactionPayload.contractCall()
.setFunction(new ContractFunction("claimFromStream"))
.addArg(new U64Value(12)) // stream id
.build();
This endpoint can be called by the sender or the recipient and will cancel a stream at any time if the stream was not marked as non-cancellable by the sender during creation. If the stream is canceled before the start time, all funds are returned to the sender. If you cancel the stream after the start time, but before the end time, the amount that was streamed so far is transferred to the recipient, and the remaining tokens come back to your wallet. If the stream is canceled after the end time, all funds are transferred to the recipient.
#[endpoint(cancelStream)]
fn cancel_stream(
&self,
stream_id: u64,
with_claim: OptionalValue<bool>
)
If you call this endpoint with the "with_claim" param "true", it will also claim your remaining funds (if any) after the cancellation.
TransactionPayload.contractCall()
.setFunction(new ContractFunction("cancelStream"))
.addArg(new U64Value(9)) // stream id
.build();
After a stream is canceled, you can call this endpoint to claim the streamed tokens as a recipient or the remaining tokens as a sender (if any). This endpoint is especially helpful when the recipient/sender is a non-payable smart contract.
For convenience, this endpoint is automatically called by default from the Cancel stream endpoint (is not instructed otherwise by the "with_claim" param).
#[endpoint(claimFromStreamAfterCancel)]
fn claim_from_stream_after_cancel(
&self,
stream_id: u64
)
TransactionPayload.contractCall()
.setFunction(new ContractFunction("claimFromStreamAfterCancel"))
.addArg(new U64Value(9)) // stream id
.build();
Last modified 9mo ago