diff --git a/package.json b/package.json index b9100b0..daa6567 100644 --- a/package.json +++ b/package.json @@ -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", @@ -94,4 +94,4 @@ "coverageDirectory": "../coverage", "testEnvironment": "node" } -} \ No newline at end of file +} diff --git a/positions/positions.controller.ts b/positions/positions.controller.ts index d759097..fb7feac 100644 --- a/positions/positions.controller.ts +++ b/positions/positions.controller.ts @@ -3,6 +3,7 @@ import { PositionsService } from './positions.service'; import { ApiMintingUpdateListing, ApiMintingUpdateMapping, + ApiPositionDefault, ApiPositionsListing, ApiPositionsMapping, ApiPositionsOwners, @@ -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', diff --git a/positions/positions.service.ts b/positions/positions.service.ts index 4a14192..7ef7093 100644 --- a/positions/positions.service.ts +++ b/positions/positions.service.ts @@ -8,6 +8,7 @@ import { CONFIG, VIEM_CONFIG } from '../api.config'; import { ApiMintingUpdateListing, ApiMintingUpdateMapping, + ApiPositionDefault, ApiPositionsListing, ApiPositionsMapping, ApiPositionsOwners, @@ -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); @@ -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 { diff --git a/positions/positions.types.ts b/positions/positions.types.ts index b2af0fa..f9e680a 100644 --- a/positions/positions.types.ts +++ b/positions/positions.types.ts @@ -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; +}; diff --git a/yarn.lock b/yarn.lock index 9b1ec5a..bbd417a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"