Skip to content
Merged
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"dependencies": {
"@apollo/client": "^3.10.5",
"@juicedollar/jusd": "^1.0.1",
"@juicedollar/jusd": "1.0.6",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.0.0",
Expand Down Expand Up @@ -94,4 +94,4 @@
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
}
9 changes: 9 additions & 0 deletions positions/positions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PositionsService } from './positions.service';
import {
ApiMintingUpdateListing,
ApiMintingUpdateMapping,
ApiPositionDefault,
ApiPositionsListing,
ApiPositionsMapping,
ApiPositionsOwners,
Expand All @@ -14,6 +15,14 @@ import { ApiResponse, ApiTags } from '@nestjs/swagger';
export class PositionsController {
constructor(private readonly positionsService: PositionsService) {}

@Get('default')
@ApiResponse({
description: 'Returns the default position for native coin minting',
})
getDefault(): ApiPositionDefault | null {
return this.positionsService.getDefaultPosition();
}

@Get('list')
@ApiResponse({
description: 'Returns a list of all positions',
Expand Down
21 changes: 21 additions & 0 deletions positions/positions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CONFIG, VIEM_CONFIG } from '../api.config';
import {
ApiMintingUpdateListing,
ApiMintingUpdateMapping,
ApiPositionDefault,
ApiPositionsListing,
ApiPositionsMapping,
ApiPositionsOwners,
Expand All @@ -18,6 +19,9 @@ import {
PositionsQueryObjectArray,
} from './positions.types';

// Genesis position address from NPM package
const GENESIS_POSITION = ADDRESS[CONFIG.chain.id].genesisPosition as Address;

@Injectable()
export class PositionsService {
private readonly logger = new Logger(this.constructor.name);
Expand All @@ -27,6 +31,23 @@ export class PositionsService {

constructor() {}

getDefaultPosition(): ApiPositionDefault | null {
const cached = this.fetchedPositions[GENESIS_POSITION.toLowerCase() as Address];
if (!cached) return null;
return {
position: cached.position,
collateral: cached.collateral,
collateralSymbol: cached.collateralSymbol,
collateralDecimals: cached.collateralDecimals,
price: cached.price,
minimumCollateral: cached.minimumCollateral,
availableForClones: cached.availableForClones,
expiration: cached.expiration,
reserveContribution: cached.reserveContribution,
annualInterestPPM: cached.annualInterestPPM,
};
}

getPositionsList(): ApiPositionsListing {
const pos = Object.values(this.fetchedPositions) as PositionQuery[];
return {
Expand Down
13 changes: 13 additions & 0 deletions positions/positions.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,16 @@ export type ApiMintingUpdateMapping = {
positions: Address[];
map: MintingUpdateQueryObjectArray;
};

export type ApiPositionDefault = {
position: Address;
collateral: Address;
collateralSymbol: string;
collateralDecimals: number;
price: string;
minimumCollateral: string;
availableForClones: string;
expiration: number;
reserveContribution: number;
annualInterestPPM: number;
};
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -902,10 +902,10 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@juicedollar/jusd@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@juicedollar/jusd/-/jusd-1.0.1.tgz#b9cd0787bd98a49c2238f0a2cb175ebb54f5cd5f"
integrity sha512-giqtQtwn+AC3gH5Ed7u/zlcT72OIanQ6/8NIFN6Hm0/nJfRUf/3ngNSqvvSXxX6zLEurU7684XTICw3wGlmGyA==
"@juicedollar/jusd@1.0.6":
version "1.0.6"
resolved "https://registry.yarnpkg.com/@juicedollar/jusd/-/jusd-1.0.6.tgz#5e28a415a71b1abd77d1c278ae2816b95fc72bb3"
integrity sha512-5fp4n5rAyq/pw6rEbCWEdJ0U5v50NHh/cR63gG+Km8aNj8GO1wxG53/cNuXku/45TWGGFsboDci18C4X8tdEOg==
dependencies:
"@openzeppelin/contracts" "^5.1.0"
hardhat-abi-exporter "^2.10.0"
Expand Down