Skip to content

Commit

Permalink
extend alternative fees to LPs
Browse files Browse the repository at this point in the history
  • Loading branch information
TalDerei committed Jan 15, 2025
1 parent 97842ea commit b886b58
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/services/src/view-service/fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,40 @@ export const extractAltFee = async (
}
}

const positionOpen = request.positionOpens
.map(assetIn => assetIn.position?.phi?.pair?.asset1)
.find(Boolean);
if (positionOpen) {
const assetId = await getAssetFromGasPriceTable(request, indexedDb, swapAsset);
if (assetId) {
return assetId;
}
}

const positionClose = request.positionCloses.map(a => a.positionId).find(Boolean);
if (positionClose) {
const closePosition = await indexedDb.getPosition(positionClose);
if (closePosition?.phi?.pair?.asset1) {
const inputAssetId = closePosition.phi.pair.asset1;
const assetId = await getAssetFromGasPriceTable(request, indexedDb, inputAssetId);
if (assetId) {
return assetId;
}
}
}

const positonWithdraw = request.positionWithdraws.map(a => a.positionId).find(Boolean);
if (positonWithdraw) {
const withdrawPosition = await indexedDb.getPosition(positonWithdraw);
if (withdrawPosition?.phi?.pair?.asset1) {
const inputAssetId = withdrawPosition.phi.pair.asset1;
const assetId = await getAssetFromGasPriceTable(request, indexedDb, inputAssetId);
if (assetId) {
return assetId;
}
}
}

if (request.undelegations.length > 0) {
const assetId = await getAssetFromGasPriceTable(request, indexedDb);
if (assetId) {
Expand Down
11 changes: 11 additions & 0 deletions packages/storage/src/indexed-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -993,4 +993,15 @@ export class IndexedDb implements IndexedDbInterface {
new Amount({ hi: 0n, lo: 0n }),
);
}

async getPosition(positionId: PositionId): Promise<Position | undefined> {
assertPositionId(positionId);
const position = await this.db.get('POSITIONS', uint8ArrayToBase64(positionId.inner));

if (!position) {
return undefined;
}

return Position.fromJson(position.position);
}
}
2 changes: 2 additions & 0 deletions packages/types/src/indexed-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export interface IndexedDbInterface {
hasTokenBalance(addressIndex: number, assetId: AssetId): Promise<boolean>;

totalNoteBalance(accountIndex: number, assetId: AssetId): Promise<Amount>;

getPosition(positionId: PositionId): Promise<Position | undefined>;
}

export interface PenumbraDb extends DBSchema {
Expand Down

0 comments on commit b886b58

Please sign in to comment.