From 1a3b6bd8764a565e5ad12c478fdd67ff846ed576 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Fri, 11 Apr 2025 14:59:53 +0200 Subject: [PATCH] Use BigInt instead of number of token values --- src/marketplace/marketplace.test.ts | 22 ++++----- src/marketplace/marketplace.ts | 6 +-- src/marketplace/types.ts | 70 ++++++++++++++++++++++------- 3 files changed, 67 insertions(+), 31 deletions(-) diff --git a/src/marketplace/marketplace.test.ts b/src/marketplace/marketplace.test.ts index dcb4433..f38eed9 100644 --- a/src/marketplace/marketplace.test.ts +++ b/src/marketplace/marketplace.test.ts @@ -33,16 +33,16 @@ describe("marketplace", async () => { describe("create", async () => { it("verifies that the availability was created successfully", async () => { assert.ok(availability.id); - assert.strictEqual(availability.duration, duration); - assert.strictEqual(availability.freeSize, totalSize); - assert.strictEqual( + assert.equal(availability.duration, duration); + assert.equal(availability.freeSize, totalSize); + assert.equal( availability.minPricePerBytePerSecond, - minPricePerBytePerSecond + BigInt(minPricePerBytePerSecond) ); - assert.strictEqual(availability.totalCollateral, totalCollateral); - assert.strictEqual( + assert.equal(availability.totalCollateral, BigInt(totalCollateral)); + assert.equal( availability.totalRemainingCollateral, - totalCollateral + BigInt(totalCollateral) ); assert.strictEqual(availability.totalSize, totalSize); assert.strictEqual(availability.until, 0); @@ -52,8 +52,8 @@ describe("marketplace", async () => { const errors: Partial[] = [ { duration: 0 }, { totalSize: 0 }, - { totalCollateral: -1 }, - { minPricePerBytePerSecond: -1 }, + { totalCollateral: BigInt(-1) }, + { minPricePerBytePerSecond: BigInt(-1) }, ]; for (const err of errors) { @@ -90,9 +90,9 @@ describe("marketplace", async () => { const updates: Omit[] = [ { enabled: false }, { duration: 3000 }, - { minPricePerBytePerSecond: 1 }, + { minPricePerBytePerSecond: BigInt(1) }, { totalSize: 3000 }, - { totalCollateral: 3000 }, + { totalCollateral: BigInt(3000) }, { until: 5000 }, ]; diff --git a/src/marketplace/marketplace.ts b/src/marketplace/marketplace.ts index 5197483..33c6d09 100644 --- a/src/marketplace/marketplace.ts +++ b/src/marketplace/marketplace.ts @@ -78,9 +78,9 @@ export class CodexMarketplace { }: CodexAvailabilityWithoutTypes) { const availability: CodexAvailability = { ...a, - minPricePerBytePerSecond: parseInt(a.minPricePerBytePerSecond, 10), - totalCollateral: parseInt(a.totalCollateral, 10), - totalRemainingCollateral: parseInt(a.totalRemainingCollateral, 10), + minPricePerBytePerSecond: BigInt(a.minPricePerBytePerSecond), + totalCollateral: BigInt(a.totalCollateral), + totalRemainingCollateral: BigInt(a.totalRemainingCollateral), }; if (freeSize) { diff --git a/src/marketplace/types.ts b/src/marketplace/types.ts index e736509..d5128c3 100644 --- a/src/marketplace/types.ts +++ b/src/marketplace/types.ts @@ -20,18 +20,14 @@ export type CodexAvailabilityWithoutTypes = export type CodexAvailability = Omit< CodexAvailabilityWithoutTypes, | "freeSize" - | "totalSize" | "minPricePerBytePerSecond" - | "duration" | "totalCollateral" | "totalRemainingCollateral" > & { freeSize?: number; - totalSize: number; - duration: number; - minPricePerBytePerSecond: number; - totalCollateral: number; - totalRemainingCollateral: number; + minPricePerBytePerSecond: BigInt; + totalCollateral: BigInt; + totalRemainingCollateral: BigInt; }; export type CodexAvailabilityCreateResponse = @@ -45,8 +41,22 @@ export type CodexAvailabilityCreateBody = Exclude< export const CodexCreateAvailabilityInput = v.strictObject({ totalSize: v.pipe(v.number(), v.minValue(1)), duration: v.pipe(v.number(), v.minValue(1)), - minPricePerBytePerSecond: v.pipe(v.number(), v.minValue(0)), - totalCollateral: v.pipe(v.number(), v.minValue(0)), + minPricePerBytePerSecond: v.union([ + v.bigint(), + v.pipe( + v.number(), + v.minValue(0), + v.transform((input) => BigInt(input)) + ), + ]), + totalCollateral: v.union([ + v.bigint(), + v.pipe( + v.number(), + v.minValue(0), + v.transform((input) => BigInt(input)) + ), + ]), enabled: v.optional(v.boolean()), until: v.optional(v.pipe(v.number(), v.minValue(0))), }); @@ -61,23 +71,49 @@ export type CodexAvailabilityPatchBody = Partial< >["content"]["application/json"] >; -export type CodexCreateAvailabilityInput = v.InferOutput< - typeof CodexCreateAvailabilityInput ->; +export type CodexCreateAvailabilityInput = Omit< + v.InferOutput, + "minPricePerBytePerSecond" | "totalCollateral" +> & { + minPricePerBytePerSecond?: number | BigInt; + totalCollateral?: number | BigInt; +}; export const CodexAvailabilityPatchInput = v.strictObject({ id: v.string(), totalSize: v.optional(v.pipe(v.number(), v.minValue(1))), duration: v.optional(v.pipe(v.number(), v.minValue(1))), - minPricePerBytePerSecond: v.optional(v.pipe(v.number(), v.minValue(1))), - totalCollateral: v.optional(v.pipe(v.number(), v.minValue(0))), + minPricePerBytePerSecond: v.optional( + v.union([ + v.bigint(), + v.pipe( + v.number(), + v.minValue(1), + v.transform((input) => BigInt(input)) + ), + ]) + ), + totalCollateral: v.optional( + v.union([ + v.bigint(), + v.pipe( + v.number(), + v.minValue(0), + v.transform((input) => BigInt(input)) + ), + ]) + ), enabled: v.optional(v.boolean()), until: v.optional(v.pipe(v.number(), v.minValue(0))), }); -export type CodexAvailabilityPatchInput = v.InferOutput< - typeof CodexAvailabilityPatchInput ->; +export type CodexAvailabilityPatchInput = Omit< + v.InferOutput, + "minPricePerBytePerSecond" | "totalCollateral" +> & { + minPricePerBytePerSecond?: number | BigInt; + totalCollateral?: number | BigInt; +}; export type CodexReservationsResponse = paths["/sales/availability/{id}/reservations"]["get"]["responses"][200]["content"]["application/json"];