interlay / interbtc-api

interBTC TypeScript SDK
https://app.interlay.io/
Apache License 2.0
26 stars 20 forks source link

Feat: enable vault withdraw all collateral #727

Closed bvotteler closed 8 months ago

bvotteler commented 8 months ago

Resolves #725

Added new endpoints to easier withdraw all collateral for vaults.

Note: Tested manually. No integration test case sadly, because all the spun up and funded vaults end up with some tokens issued or to-be-issued left over from previous non-idempotent test cases.

sander2 commented 8 months ago

No integration test case sadly, because all the spun up and funded vaults end up with some tokens issued or to-be-issued left over from previous non-idempotent test cases. Could you not do a selfredeem? (there is a special tx for selfredeem that doesn't involve any btc payments)

bvotteler commented 8 months ago

Could you not do a selfredeem? (there is a special tx for selfredeem that doesn't involve any btc payments)

I tried a few angles with the existing test redeem utility code but had no luck. Or at least it didn't settle immediately. I can give self redeem a try, I'd expect that requires the vault to get enough tokens issued from somewhere else, right?

bvotteler commented 8 months ago

lgtm. Would it be useful to provide a canWithdrawAll or something for the UI? Or can UI easily detect that already?

There are a few methods that should do the trick already. The two first that come to mind are:

  1. vaultsAPI.getVaultCollateralization() (link) returns undefined if no tokens have been issued, or
  2. Fetch vault by account id and collateral currency to get a VaultExt instance, then query for backed tokens which includes both issued and to-be-issued tokens:
    const vaultExt = await vaultsApi.get(vaultAccountId, collateralCurrency));
    const issuedAmount = vaultExt.getBackedTokens(); // includes to-be-issued

    (Link to signature for get, and link to getBackedTokens)

sander2 commented 8 months ago

Could you not do a selfredeem? (there is a special tx for selfredeem that doesn't involve any btc payments)

I tried a few angles with the existing test redeem utility code but had no luck. Or at least it didn't settle immediately. I can give self redeem a try, I'd expect that requires the vault to get enough tokens issued from somewhere else, right?

Yea that's right (but u could just sudo-mint some if you don't mind some state inconsistencies)

bvotteler commented 8 months ago

Could you not do a selfredeem? (there is a special tx for selfredeem that doesn't involve any btc payments)

I tried a few angles with the existing test redeem utility code but had no luck. Or at least it didn't settle immediately. I can give self redeem a try, I'd expect that requires the vault to get enough tokens issued from somewhere else, right?

Yea that's right (but u could just sudo-mint some if you don't mind some state inconsistencies)

Thanks for the self redeem tip! That helped in adding a test: commit 252682f