@@ -75,15 +75,15 @@ export class SubtopiaClient {
7575 subscriptionName : string ;
7676 algodClient : algosdk . Algodv2 ;
7777 creator : TransactionSignerAccount ;
78- price : number ;
78+ price : bigint ;
7979 coin : AssetMetadata ;
80- oracleID : number ;
80+ oracleID : bigint ;
8181 version : string ;
82- appID : number ;
82+ appID : bigint ;
8383 appAddress : Address ;
8484 appSpec : ApplicationSpec ;
8585 timeout : number ;
86- registryID : number ;
86+ registryID : bigint ;
8787
8888 protected constructor ( {
8989 algodClient,
@@ -105,14 +105,14 @@ export class SubtopiaClient {
105105 subscriptionName : string ;
106106 creator : TransactionSignerAccount ;
107107 appSpec : ApplicationSpec ;
108- appID : number ;
108+ appID : bigint ;
109109 appAddress : Address ;
110- oracleID : number ;
111- price : number ;
110+ oracleID : bigint ;
111+ price : bigint ;
112112 coin : AssetMetadata ;
113113 version : string ;
114114 timeout : number ;
115- registryID : number ;
115+ registryID : bigint ;
116116 } ) {
117117 this . algodClient = algodClient ;
118118 this . productName = productName ;
@@ -175,9 +175,9 @@ export class SubtopiaClient {
175175 throw new Error ( "Oracle missing, cannot initialize" ) ;
176176 }
177177
178- const oracleID = productGlobalState . oracle_id ;
178+ const oracleID = BigInt ( productGlobalState . oracle_id ) ;
179179 const productAddress = getApplicationAddress ( productID ) ;
180- const productPrice = Number ( productGlobalState . price ) ;
180+ const productPrice = BigInt ( productGlobalState . price ) ;
181181 const productSpec = await getAppById ( productID , algodClient ) ;
182182 const productName = productGlobalState . product_name ;
183183 const subscriptionName = productGlobalState . subscription_name ;
@@ -227,20 +227,19 @@ export class SubtopiaClient {
227227 appSpec : {
228228 approval : productSpec . params . approvalProgram ,
229229 clear : productSpec . params . clearStateProgram ,
230- globalNumUint :
231- Number ( productSpec . params . globalStateSchema ?. numUint ) || 0 ,
230+ globalNumUint : productSpec . params . globalStateSchema ?. numUint || 0 ,
232231 globalNumByteSlice :
233- Number ( productSpec . params . globalStateSchema ?. numByteSlice ) || 0 ,
234- localNumUint : Number ( productSpec . params . localStateSchema ?. numUint ) || 0 ,
232+ productSpec . params . globalStateSchema ?. numByteSlice || 0 ,
233+ localNumUint : productSpec . params . localStateSchema ?. numUint || 0 ,
235234 localNumByteSlice :
236- Number ( productSpec . params . localStateSchema ?. numByteSlice ) || 0 ,
235+ productSpec . params . localStateSchema ?. numByteSlice || 0 ,
237236 } ,
238237 oracleID,
239238 price : productPrice ,
240239 coin,
241240 version,
242241 timeout,
243- registryID : registryId ,
242+ registryID : BigInt ( registryId ) ,
244243 } ) ;
245244 }
246245
@@ -336,19 +335,19 @@ export class SubtopiaClient {
336335 manager : globalState . manager ,
337336 price : parseWholeUnits
338337 ? normalizePrice (
339- Number ( globalState . price ) ,
338+ BigInt ( globalState . price ) ,
340339 this . coin . decimals ,
341340 PriceNormalizationType . PRETTY ,
342341 )
343- : globalState . price ,
344- totalSubs : Number ( globalState . total_subscribers ) ,
345- maxSubs : Number ( globalState . max_subscribers ) ,
346- coinID : Number ( globalState . coin_id ) ,
347- productType : Number ( globalState . product_type ) ,
348- lifecycle : Number ( globalState . lifecycle ) ,
349- createdAt : Number ( globalState . created_at ) ,
350- duration : Number ( globalState . duration ) ,
351- oracleID : Number ( globalState . oracle_id ) ,
342+ : BigInt ( globalState . price ) ,
343+ totalSubs : BigInt ( globalState . total_subscribers ) ,
344+ maxSubs : BigInt ( globalState . max_subscribers ) ,
345+ coinID : BigInt ( globalState . coin_id ) ,
346+ productType : globalState . product_type ,
347+ lifecycle : BigInt ( globalState . lifecycle ) ,
348+ createdAt : BigInt ( globalState . created_at ) ,
349+ duration : globalState . duration ,
350+ oracleID : BigInt ( globalState . oracle_id ) ,
352351 unitName : String ( globalState . unit_name ) ,
353352 imageURL : String ( globalState . image_url ) ,
354353 discount : discount ,
@@ -357,12 +356,12 @@ export class SubtopiaClient {
357356
358357 /**
359358 * This method calculates the platform fee for a subscription.
360- * It returns the platform fee as a number .
361- * @returns {Promise<number > } A promise that resolves to the platform fee.
359+ * It returns the platform fee as a bigint .
360+ * @returns {Promise<bigint > } A promise that resolves to the platform fee.
362361 */
363- public async getSubscriptionPlatformFee ( ) : Promise < number > {
364- if ( this . price === 0 ) {
365- return new Promise ( ( resolve ) => resolve ( 0 ) ) ;
362+ public async getSubscriptionPlatformFee ( ) : Promise < bigint > {
363+ if ( this . price === 0n ) {
364+ return new Promise ( ( resolve ) => resolve ( 0n ) ) ;
366365 }
367366
368367 const priceInCents = SUBSCRIPTION_PLATFORM_FEE_CENTS ;
@@ -408,7 +407,7 @@ export class SubtopiaClient {
408407 request ,
409408 ) ;
410409
411- return Number ( response . methodResults [ 0 ] . returnValue ) ;
410+ return BigInt ( response . methodResults [ 0 ] . returnValue as string ) ;
412411 }
413412
414413 /**
@@ -479,18 +478,18 @@ export class SubtopiaClient {
479478 return undefined ;
480479 }
481480
482- const boxContent : Array < number > = Array . isArray ( rawContent )
483- ? rawContent . map ( ( value ) => Number ( value ) )
481+ const boxContent : Array < bigint > = Array . isArray ( rawContent )
482+ ? rawContent . map ( ( value ) => BigInt ( value ) )
484483 : [ ] ;
485484
486485 if ( boxContent . length !== 5 ) {
487486 throw new Error ( "Invalid subscription record" ) ;
488487 }
489488
490489 return {
491- discountType : boxContent [ 0 ] ,
490+ discountType : Number ( boxContent [ 0 ] ) ,
492491 discountValue : boxContent [ 1 ] ,
493- expiresAt : boxContent [ 2 ] === 0 ? null : boxContent [ 2 ] ,
492+ expiresAt : boxContent [ 2 ] === 0n ? null : boxContent [ 2 ] ,
494493 createdAt : boxContent [ 3 ] ,
495494 totalClaims : boxContent [ 4 ] ,
496495 } ;
@@ -626,13 +625,13 @@ export class SubtopiaClient {
626625 * This method is utilized to initiate a subscription.
627626 * It accepts a subscriber as an argument and returns a promise that resolves to an object containing the transaction ID and subscription ID.
628627 * @param {ProductSubscriptionCreationParams } params - The parameters for creating a subscription.
629- * @returns {Promise<{txID: string, subscriptionID: number }> } A promise that resolves to an object containing the transaction ID and subscription ID.
628+ * @returns {Promise<{txID: string, subscriptionID: bigint }> } A promise that resolves to an object containing the transaction ID and subscription ID.
630629 */
631630 public async createSubscription (
632631 params : ProductSubscriptionCreationParams ,
633632 ) : Promise < {
634633 txID : string ;
635- subscriptionID : number ;
634+ subscriptionID : bigint ;
636635 } > {
637636 const { subscriber } = params ;
638637 const oracleAdminState = (
@@ -663,7 +662,7 @@ export class SubtopiaClient {
663662 if ( state . discount . discountType === DiscountType . PERCENTAGE ) {
664663 subscriptionPrice =
665664 subscriptionPrice -
666- ( subscriptionPrice * state . discount . discountValue ) / 100 ;
665+ ( subscriptionPrice * state . discount . discountValue ) / 100n ;
667666 } else if ( state . discount . discountType === DiscountType . FIXED ) {
668667 subscriptionPrice = subscriptionPrice - state . discount . discountValue ;
669668 }
@@ -746,7 +745,7 @@ export class SubtopiaClient {
746745 } ) ,
747746 signer : subscriber . signer ,
748747 } ,
749- this . coin . index === 0
748+ this . coin . index === 0n
750749 ? {
751750 txn : makePaymentTxnWithSuggestedParamsFromObject ( {
752751 sender : subscriber . addr ,
@@ -802,7 +801,7 @@ export class SubtopiaClient {
802801
803802 return {
804803 txID : response . txIDs . pop ( ) as string ,
805- subscriptionID : Number ( response . methodResults [ 0 ] . returnValue ) ,
804+ subscriptionID : BigInt ( response . methodResults [ 0 ] . returnValue as string ) ,
806805 } ;
807806 }
808807
@@ -1105,20 +1104,20 @@ export class SubtopiaClient {
11051104 } ) ;
11061105
11071106 const response = await getSubscriptionAtc . simulate ( algodClient , request ) ;
1108- const boxContent : Array < number > = (
1109- response . methodResults [ 0 ] . returnValue ?. valueOf ( ) as Array < number >
1110- ) . map ( ( value ) => Number ( value ) ) ;
1107+ const boxContent : Array < bigint > = (
1108+ response . methodResults [ 0 ] . returnValue ?. valueOf ( ) as Array < bigint >
1109+ ) . map ( ( value ) => BigInt ( value ) ) ;
11111110
11121111 if ( boxContent . length !== 5 ) {
11131112 throw new Error ( "Invalid subscription record" ) ;
11141113 }
11151114
11161115 return {
11171116 subscriptionID : boxContent [ 0 ] ,
1118- productType : boxContent [ 1 ] ,
1117+ productType : Number ( boxContent [ 1 ] ) ,
11191118 createdAt : boxContent [ 2 ] ,
1120- expiresAt : boxContent [ 3 ] === 0 ? null : boxContent [ 3 ] ,
1121- duration : boxContent [ 4 ] ,
1119+ expiresAt : boxContent [ 3 ] === 0n ? null : boxContent [ 3 ] ,
1120+ duration : Number ( boxContent [ 4 ] ) ,
11221121 } ;
11231122 }
11241123
@@ -1161,7 +1160,7 @@ export class SubtopiaClient {
11611160 ? subscriberRecords . filter ( ( record ) => {
11621161 return (
11631162 record . subscription . expiresAt === null ||
1164- record . subscription . expiresAt > Date . now ( ) / 1000
1163+ record . subscription . expiresAt > BigInt ( Date . now ( ) / 1000 )
11651164 ) ;
11661165 } )
11671166 : subscriberRecords ;
0 commit comments