-
Notifications
You must be signed in to change notification settings - Fork 3
feat: implement staking #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nikdim03
wants to merge
15
commits into
main
Choose a base branch
from
feature/ton-636-staking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ca6c017
feat: implement staking
nikdim03 74fd153
chore: revert unrelated models
nikdim03 8aa75bf
chore: revert unrelated models
nikdim03 2426c23
chore: restore removed models
nikdim03 008630f
chore: update mjs
nikdim03 46d3389
refactor: update APY field type to Double
nikdim03 a4a30f2
chore: remove excessive comments
nikdim03 9ab3d1a
chore: update models & mjs
nikdim03 1ee03a8
chore: update models
nikdim03 67e0710
Merge branch 'main' into feature/ton-636-staking
nikdim03 f7e4782
refactor: replace providerId with typed identifiers & make ITONTonSta…
nikdim03 ad774b6
chore: update models
nikdim03 ca13cf8
chore: change apy to double
nikdim03 6eab785
feat: update android model generation to handle floating-point values…
nikdim03 8b8a933
chore: remove swap models change from pr
nikdim03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
TONWalletKit-Android/api/src/main/java/io/ton/walletkit/ITONStakingManager.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| /* | ||
| * Copyright (c) 2025 TonTech | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
| package io.ton.walletkit | ||
|
|
||
| import io.ton.walletkit.api.generated.TONNetwork | ||
| import io.ton.walletkit.api.generated.TONStakeParams | ||
| import io.ton.walletkit.api.generated.TONStakingBalance | ||
| import io.ton.walletkit.api.generated.TONStakingProviderInfo | ||
| import io.ton.walletkit.api.generated.TONStakingQuote | ||
| import io.ton.walletkit.api.generated.TONStakingQuoteParams | ||
| import io.ton.walletkit.api.generated.TONTransactionRequest | ||
| import io.ton.walletkit.api.generated.TONUnstakeMode | ||
| import io.ton.walletkit.model.TONUserFriendlyAddress | ||
| import kotlinx.serialization.json.JsonElement | ||
|
|
||
| /** | ||
| * Manages staking providers and exposes staking operations. | ||
| */ | ||
| interface ITONStakingManager { | ||
|
|
||
| /** | ||
| * Register a staking provider created via [ITONWalletKit.tonStakersStakingProvider]. | ||
| */ | ||
| suspend fun register(provider: ITONTonStakersStakingProvider) | ||
|
|
||
| /** | ||
| * Set the default provider used when no providerId is passed to query methods. | ||
| * | ||
| * @param providerId The [ITONTonStakersStakingProvider.identifier] of the provider to use by default | ||
| */ | ||
| fun setDefaultProvider(providerId: TONStakingProviderIdentifier) | ||
|
|
||
| /** | ||
| * Get a stake or unstake quote. | ||
| * | ||
| * @param params Quote parameters including direction, amount, and optional fields | ||
| * @param providerId Override which provider to use (uses default when null) | ||
| * @return Staking quote with input/output amounts and metadata | ||
| */ | ||
| suspend fun getQuote( | ||
| params: TONStakingQuoteParams<JsonElement>, | ||
| providerId: TONStakingProviderIdentifier? = null, | ||
| ): TONStakingQuote | ||
|
|
||
| /** | ||
| * Build a stake or unstake transaction from a previously obtained quote. | ||
| * | ||
| * The returned [TONTransactionRequest] can be passed to [ITONWallet.send]. | ||
| * | ||
| * @param params Stake parameters including the quote and user address | ||
| * @param providerId Override which provider to use (uses default when null) | ||
| * @return Transaction request ready for [ITONWallet.send] or [ITONWallet.preview] | ||
| */ | ||
| suspend fun buildStakeTransaction( | ||
| params: TONStakeParams<JsonElement>, | ||
| providerId: TONStakingProviderIdentifier? = null, | ||
| ): TONTransactionRequest | ||
|
|
||
| /** | ||
| * Get the user's staked balance. | ||
| * | ||
| * @param userAddress User's wallet address | ||
| * @param network TON network (uses current network when null) | ||
| * @param providerId Override which provider to use (uses default when null) | ||
| * @return Staking balance including staked amount and instant-unstake availability | ||
| */ | ||
| suspend fun getStakedBalance( | ||
| userAddress: TONUserFriendlyAddress, | ||
| network: TONNetwork? = null, | ||
| providerId: TONStakingProviderIdentifier? = null, | ||
| ): TONStakingBalance | ||
|
|
||
| /** | ||
| * Get general information about a staking provider (APY, instant-unstake liquidity). | ||
| * | ||
| * @param network TON network (uses current network when null) | ||
| * @param providerId Override which provider to use (uses default when null) | ||
| * @return Provider info including APY as a percentage value | ||
| */ | ||
| suspend fun getStakingProviderInfo( | ||
| network: TONNetwork? = null, | ||
| providerId: TONStakingProviderIdentifier? = null, | ||
| ): TONStakingProviderInfo | ||
|
|
||
| /** | ||
| * Get the unstake modes supported by a staking provider. | ||
| * | ||
| * @param providerId Override which provider to use (uses default when null) | ||
| * @return List of supported unstake modes | ||
| */ | ||
| suspend fun getSupportedUnstakeModes( | ||
| providerId: TONStakingProviderIdentifier? = null, | ||
| ): List<TONUnstakeMode> | ||
| } | ||
|
|
||
| /** | ||
| * Represents a registered TonStakers staking provider. | ||
| * | ||
| * Created via [ITONWalletKit.tonStakersStakingProvider] and registered with [ITONStakingManager.register]. | ||
| */ | ||
| interface ITONTonStakersStakingProvider { | ||
| /** Typed staking provider identifier recognised by [ITONStakingManager]. */ | ||
| val identifier: TONTonStakersStakingProviderIdentifier | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
TONWalletKit-Android/api/src/main/java/io/ton/walletkit/TONProviderIdentifier.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright (c) 2025 TonTech | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
| package io.ton.walletkit | ||
|
|
||
| /** | ||
| * Typed provider identifier used by public SDK APIs instead of raw strings. | ||
| */ | ||
| interface TONProviderIdentifier { | ||
| val name: String | ||
| } | ||
|
|
||
| /** | ||
| * Type-erased provider identifier. | ||
| */ | ||
| data class AnyTONProviderIdentifier( | ||
| override val name: String, | ||
| ) : TONProviderIdentifier | ||
|
|
||
| /** | ||
| * Marker interface for staking provider identifiers. | ||
| */ | ||
| interface TONStakingProviderIdentifier : TONProviderIdentifier | ||
|
|
||
| /** | ||
| * Identifier for the TonStakers staking provider. | ||
| */ | ||
| data class TONTonStakersStakingProviderIdentifier( | ||
| override val name: String = DEFAULT_NAME, | ||
| ) : TONStakingProviderIdentifier { | ||
| companion object { | ||
| const val DEFAULT_NAME = "tonstakers" | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
TONWalletKit-Android/api/src/main/java/io/ton/walletkit/api/TONTonStakersProviderConfig.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Copyright (c) 2025 TonTech | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
| package io.ton.walletkit.api | ||
|
|
||
| import io.ton.walletkit.api.generated.TONTonStakersChainConfig | ||
|
|
||
| /** | ||
| * Per-chain configuration for the TonStakers staking provider. | ||
| * | ||
| * The underlying JS API uses an index-signature type `{ [chainId: string]: TonStakersChainConfig }` | ||
| * where chainIds are "-239" (mainnet) and "-3" (testnet). This class provides a named-field | ||
| * alternative that converts to the required map via [toChainConfigMap]. | ||
| */ | ||
| data class TONTonStakersProviderConfig( | ||
| val mainnet: TONTonStakersChainConfig? = null, | ||
| val testnet: TONTonStakersChainConfig? = null, | ||
| ) { | ||
| fun toChainConfigMap(): Map<String, TONTonStakersChainConfig> = buildMap { | ||
| mainnet?.let { put("-239", it) } | ||
| testnet?.let { put("-3", it) } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
TONWalletKit-Android/api/src/main/java/io/ton/walletkit/api/generated/TONStakeParams.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright (c) 2025 TonTech | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
| @file:Suppress( | ||
| "ArrayInDataClass", | ||
| "EnumEntryName", | ||
| "RemoveRedundantQualifierName", | ||
| "UnusedImport", | ||
| ) | ||
|
|
||
| package io.ton.walletkit.api.generated | ||
|
|
||
| import io.ton.walletkit.model.TONUserFriendlyAddress | ||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| /** | ||
| * | ||
| * | ||
| * @param quote | ||
| * @param userAddress | ||
| * @param providerOptions Provider-specific options | ||
| */ | ||
| @Serializable | ||
| data class TONStakeParams<TProviderOptions>( | ||
| @SerialName("quote") | ||
| val quote: TONStakingQuote, | ||
| @SerialName("userAddress") | ||
| val userAddress: io.ton.walletkit.model.TONUserFriendlyAddress, | ||
| @SerialName("providerOptions") | ||
| val providerOptions: TProviderOptions? = null, | ||
| ) { | ||
| companion object | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.