Skip to content

Commit

Permalink
Merge pull request #287 from anton-karlovskiy/feature/redeemable-tokens
Browse files Browse the repository at this point in the history
feat: add redeemable tokens case
  • Loading branch information
nud3l authored May 26, 2021
2 parents 022bba6 + 0fb18f3 commit 015bbd1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/parachain/vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ export interface VaultsAPI extends TransactionAPI {
* @returns Vaults with issuable tokens, sorted in descending order of this value
*/
getVaultsWithIssuableTokens(): Promise<Map<AccountId, Big>>;
/**
* @returns Vaults with redeemable tokens, sorted in descending order of this value
*/
getVaultsWithRedeemableTokens(): Promise<Map<AccountId, Big>>;
/**
* @param vaultId The vault account ID
* @returns A bollean value
Expand Down Expand Up @@ -509,13 +513,24 @@ export class DefaultVaultsAPI extends DefaultTransactionAPI implements VaultsAPI
try {
const vaults = await this.api.rpc.vaultRegistry.getVaultsWithIssuableTokens();
return new Map(
vaults.map(([id, redeemableTokens]) => [id, new Big(satToBTC(this.unwrapCurrency(redeemableTokens).toString()))])
vaults.map(([id, issuableTokens]) => [id, new Big(satToBTC(this.unwrapCurrency(issuableTokens).toString()))])
);
} catch (e) {
return Promise.reject("Did not find vault with issuable tokens");
}
}

async getVaultsWithRedeemableTokens(): Promise<Map<AccountId, Big>> {
try {
const vaults = await this.api.rpc.vaultRegistry.getVaultsWithRedeemableTokens();
return new Map(
vaults.map(([id, redeemableTokens]) => [id, new Big(satToBTC(this.unwrapCurrency(redeemableTokens).toString()))])
);
} catch (e) {
return Promise.reject("Did not find vault with redeemable tokens");
}
}

async isVaultFlaggedForTheft(vaultId: AccountId): Promise<boolean> {
const head = await this.api.rpc.chain.getFinalizedHead();
const theftReports = await this.api.query.stakedRelayers.theftReports.at(head, vaultId);
Expand Down
3 changes: 3 additions & 0 deletions test/mock/parachain/vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export class MockVaultsAPI extends MockTransactionAPI implements VaultsAPI {
getVaultsWithIssuableTokens(): Promise<Map<AccountId, Big>> {
throw new Error("Method not implemented.");
}
getVaultsWithRedeemableTokens(): Promise<Map<AccountId, Big>> {
throw new Error("Method not implemented.");
}
isVaultFlaggedForTheft(vaultId: AccountId): Promise<boolean> {
throw new Error("Method not implemented.");
}
Expand Down

0 comments on commit 015bbd1

Please sign in to comment.