Skip to content

Commit

Permalink
Merge pull request #645 from interlay/peter/feat-issue-custom-griefin…
Browse files Browse the repository at this point in the history
…g-collateral-currency

Peter/feat issue custom griefing collateral currency
  • Loading branch information
peterslany authored Jun 20, 2023
2 parents 1d03231 + 3feea71 commit 50caaa3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@interlay/interbtc-api",
"version": "2.3.3",
"version": "2.3.4",
"description": "JavaScript library to interact with interBTC",
"main": "build/src/index.js",
"typings": "build/src/index.d.ts",
Expand Down
20 changes: 13 additions & 7 deletions src/parachain/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ export interface IssueAPI {
*
* @param vaultId The vault ID of the vault to issue with.
* @param amount wrapped token amount to issue.
* @param griefingCollateralCurrency (optional) Currency in which griefing collateral will be locked.
* @returns An execute issue submittable extrinsic.
*/
buildRequestIssueExtrinsic(
vaultId: InterbtcPrimitivesVaultId,
amount: MonetaryAmount<WrappedCurrency>
amount: MonetaryAmount<WrappedCurrency>,
griefingCollateralCurrency?: CurrencyExt
): SubmittableExtrinsic<"promise", ISubmittableResult>;

/**
Expand Down Expand Up @@ -81,11 +83,13 @@ export interface IssueAPI {
* @param amountsPerVault A mapping of vaults to issue from, and wrapped token amounts to issue using each vault
* @param atomic Whether the issue request should be handled atomically or not. Only makes a difference if more than
* one vault is needed to fulfil it.
* @param griefingCollateralCurrency (optional) Currency in which griefing collateral will be locked.
* @returns {ExtrinsicData} A submittable extrinsic and an event that is emitted when extrinsic is submitted.
*/
requestAdvanced(
amountsPerVault: Map<InterbtcPrimitivesVaultId, MonetaryAmount<WrappedCurrency>>,
atomic: boolean
atomic: boolean,
griefingCollateralCurrency?: CurrencyExt
): ExtrinsicData;

/**
Expand Down Expand Up @@ -217,7 +221,8 @@ export class DefaultIssueAPI implements IssueAPI {
vaultAccountId?: AccountId,
collateralCurrency?: CollateralCurrencyExt,
atomic: boolean = true,
cachedVaults?: Map<InterbtcPrimitivesVaultId, MonetaryAmount<WrappedCurrency>>
cachedVaults?: Map<InterbtcPrimitivesVaultId, MonetaryAmount<WrappedCurrency>>,
griefingCollateralCurrency?: CurrencyExt
): Promise<ExtrinsicData> {
try {
if (vaultAccountId) {
Expand All @@ -238,11 +243,11 @@ export class DefaultIssueAPI implements IssueAPI {
const amountsPerVault = new Map<InterbtcPrimitivesVaultId, MonetaryAmount<WrappedCurrency>>([
[vaultId, amount],
]);
return this.requestAdvanced(amountsPerVault, atomic);
return this.requestAdvanced(amountsPerVault, atomic, griefingCollateralCurrency);
}
const availableVaults = cachedVaults || (await this.vaultsAPI.getVaultsWithIssuableTokens());
const amountsPerVault = allocateAmountsToVaults(availableVaults, amount);
return this.requestAdvanced(amountsPerVault, atomic);
return this.requestAdvanced(amountsPerVault, atomic, griefingCollateralCurrency);
} catch (e) {
return Promise.reject(e);
}
Expand All @@ -263,10 +268,11 @@ export class DefaultIssueAPI implements IssueAPI {

requestAdvanced(
amountsPerVault: Map<InterbtcPrimitivesVaultId, MonetaryAmount<WrappedCurrency>>,
atomic: boolean
atomic: boolean,
griefingCollateralCurrency?: CurrencyExt
): ExtrinsicData {
const txs = Array.from(amountsPerVault.entries()).map(([vaultId, amount]) =>
this.buildRequestIssueExtrinsic(vaultId, amount)
this.buildRequestIssueExtrinsic(vaultId, amount, griefingCollateralCurrency)
);
const batch = this.transactionAPI.buildBatchExtrinsic(txs, atomic);
return { extrinsic: batch, event: this.api.events.issue.RequestIssue };
Expand Down

0 comments on commit 50caaa3

Please sign in to comment.