@loktin/sdk / target-savings / TargetSavings
Class: TargetSavings
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:57
Target Savings for the configured publicKey, with one integrator. Every write acts for publicKey, and every check that needs no chain data runs before any network call.
Constructors
Constructor
new TargetSavings(
loktin,options):TargetSavings
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:66
Checks the options, with no network call.
Parameters
loktin
options
Returns
TargetSavings
Properties
integrator
readonlyintegrator:string
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:59
The integrator's address.
integratorFeeBps
readonlyintegratorFeeBps:number
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:61
The integrator fee new goals receive.
Methods
accruedFees()
accruedFees(
recipient?):Promise<bigint>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:137
Returns the fees accrued to recipient and not yet claimed (W63). recipient defaults to the module's integrator.
Parameters
recipient?
string
Returns
Promise<bigint>
allowanceStatus()
allowanceStatus(
goalId):Promise<AllowanceStatus>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:105
Reads the goal and the token allowance of publicKey for Target Savings, in parallel, and says whether the next collection would be short on allowance. The allowance is shared by all the owner's goals, so other goals' collections use it up too. It does not check the owner's balance.
Parameters
goalId
bigint
Returns
Promise<AllowanceStatus>
claimFees()
claimFees():
Promise<WriteResult<bigint>>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:132
Pays out every fee accrued to publicKey and returns the amount (W63). The call acts for publicKey, so it needs only the configured signer. An integrator claims by creating the SDK with its own publicKey and signer, and Loktin's fee recipient claims the same way. With nothing accrued, the contract refuses it with NothingToClaim. Never uses the read adapter.
Returns
Promise<WriteResult<bigint>>
collect()
collect(
goalId):Promise<WriteResult<null>>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:88
Collects the deposit for the goal's current period. Any goal may be collected (C3).
Parameters
goalId
bigint
Returns
Promise<WriteResult<null>>
createGoal()
createGoal(
input):Promise<CreatedGoal>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:77
Creates a goal for publicKey and returns its id. Ids are not sequential: each comes from the owner and its own counter. With 'auto', the allowance covers the scheduled deposits of all the owner's open goals and the new one, because an approval replaces the owner's whole Target Savings allowance (W116). It reads the owner's open goals and the ledger in parallel before the write. The returned allowance is the combined one. The deadline is rounded down to the second.
Parameters
input
Returns
Promise<CreatedGoal>
deposit()
deposit(
goalId,amount):Promise<WriteResult<null>>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:79
Deposits amount from publicKey into their goal (P7).
Parameters
goalId
bigint
amount
bigint
Returns
Promise<WriteResult<null>>
feeRecipient()
feeRecipient():
Promise<string>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:121
Returns the address Loktin fees are paid to.
Returns
Promise<string>
goal()
goal(
goalId):Promise<Goal>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:107
Returns an open goal.
Parameters
goalId
bigint
Returns
Promise<Goal>
loktinFeeBps()
loktinFeeBps():
Promise<number>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:119
Returns the Loktin fee rate new goals receive.
Returns
Promise<number>
minCadence()
minCadence():
Promise<number>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:123
Returns the shortest cadence a goal may use, in seconds.
Returns
Promise<number>
paused()
paused():
Promise<boolean>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:139
Returns whether Target Savings is paused.
Returns
Promise<boolean>
previewWithdraw()
previewWithdraw(
goalId):Promise<GoalWithdrawal>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:115
Returns how a withdrawal of the goal would split right now.
Parameters
goalId
bigint
Returns
Promise<GoalWithdrawal>
renewAllowance()
renewAllowance(
goalId):Promise<RenewedAllowance>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:97
Approves a new allowance for the remaining scheduled deposits of all the owner's open goals, goalId among them: each worked out with scheduledAllowance, then combined with combineAllowances. An approval replaces the owner's whole Target Savings allowance, which covers all their goals (W57, W116). Reads the goals from the chain, never from the adapter.
Parameters
goalId
bigint
Returns
Promise<RenewedAllowance>
token()
token():
Promise<string>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:117
Returns the token Target Savings holds.
Returns
Promise<string>
userGoals()
userGoals(
owner?):Promise<readonlyGoal[]>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:113
Returns the open goals of owner, at most 20. owner defaults to publicKey. To find every goal, read the goal_created and goal_closed events instead.
Parameters
owner?
string
Returns
Promise<readonly Goal[]>
withdraw()
withdraw(
goalId):Promise<WriteResult<GoalWithdrawal>>
Defined in: @loktin/sdk/dist/target-savings/target-savings.d.ts:86
Withdraws the whole goal of publicKey and closes it (P5, P6, R2). The owner receives toUser. The penalty and integrator fee accrue to the integrator, and the Loktin fee to Loktin's fee recipient, who each claim them with TargetSavings.claimFees.
Parameters
goalId
bigint
Returns
Promise<WriteResult<GoalWithdrawal>>