@@ -4,11 +4,14 @@ import { getContract, GetContractReturnType, Hash, WalletClient } from 'viem';
4
4
import { IJPYC , JPYC_V2_ABI } from './interfaces' ;
5
5
import {
6
6
Address ,
7
+ restoreDecimals ,
7
8
Bytes32 ,
8
9
InvalidAddressError ,
9
10
InvalidTransactionError ,
10
11
isValidAddress ,
11
12
LOCAL_PROXY_ADDRESS ,
13
+ removeDecimals ,
14
+ toUint256 ,
12
15
V2_PROXY_ADDRESS ,
13
16
} from './utils' ;
14
17
@@ -39,42 +42,42 @@ export class JPYC implements IJPYC {
39
42
return resp as boolean ;
40
43
}
41
44
42
- async minterAllowance ( params : { minter : Address } ) : Promise < Uint256 > {
45
+ async minterAllowance ( params : { minter : Address } ) : Promise < number > {
43
46
const resp = await this . contract . read . minterAllowance ( [ params . minter ] ) ;
44
47
45
- return Uint256 . from ( ( resp as bigint ) . toString ( ) ) ;
48
+ return restoreDecimals ( Uint256 . from ( resp as string ) ) ;
46
49
}
47
50
48
- async totalSupply ( ) : Promise < Uint256 > {
51
+ async totalSupply ( ) : Promise < number > {
49
52
const resp = await this . contract . read . totalSupply ( ) ;
50
53
51
- return Uint256 . from ( ( resp as bigint ) . toString ( ) ) ;
54
+ return restoreDecimals ( Uint256 . from ( resp as string ) ) ;
52
55
}
53
56
54
- async balanceOf ( params : { account : Address } ) : Promise < Uint256 > {
57
+ async balanceOf ( params : { account : Address } ) : Promise < number > {
55
58
const resp = await this . contract . read . balanceOf ( [ params . account ] ) ;
56
59
57
- return Uint256 . from ( ( resp as bigint ) . toString ( ) ) ;
60
+ return restoreDecimals ( Uint256 . from ( resp as string ) ) ;
58
61
}
59
62
60
- async allowance ( params : { owner : Address ; spender : Address } ) : Promise < Uint256 > {
63
+ async allowance ( params : { owner : Address ; spender : Address } ) : Promise < number > {
61
64
const resp = await this . contract . read . allowance ( [ params . owner , params . spender ] ) ;
62
65
63
- return Uint256 . from ( ( resp as bigint ) . toString ( ) ) ;
66
+ return restoreDecimals ( Uint256 . from ( resp as string ) ) ;
64
67
}
65
68
66
69
async nonces ( params : { owner : Address } ) : Promise < Uint256 > {
67
70
const resp = await this . contract . read . nonces ( [ params . owner ] ) ;
68
71
69
- return Uint256 . from ( ( resp as bigint ) . toString ( ) ) ;
72
+ return toUint256 ( resp as bigint ) ;
70
73
}
71
74
72
75
/**
73
- * Regular Functions
76
+ * Mutation Functions
74
77
*/
75
78
76
- async configureMinter ( params : { minter : Address ; minterAllowedAmount : Uint256 } ) : Promise < Hash > {
77
- const args = [ params . minter , params . minterAllowedAmount ] ;
79
+ async configureMinter ( params : { minter : Address ; minterAllowedAmount : number } ) : Promise < Hash > {
80
+ const args = [ params . minter , removeDecimals ( params . minterAllowedAmount ) ] ;
78
81
79
82
try {
80
83
await this . contract . simulate . configureMinter ( args ) ;
@@ -85,8 +88,8 @@ export class JPYC implements IJPYC {
85
88
return await this . contract . write . configureMinter ( args ) ;
86
89
}
87
90
88
- async mint ( params : { to : Address ; amount : Uint256 } ) : Promise < Hash > {
89
- const args = [ params . to , params . amount ] ;
91
+ async mint ( params : { to : Address ; amount : number } ) : Promise < Hash > {
92
+ const args = [ params . to , removeDecimals ( params . amount ) ] ;
90
93
91
94
try {
92
95
await this . contract . simulate . mint ( args ) ;
@@ -97,8 +100,8 @@ export class JPYC implements IJPYC {
97
100
return await this . contract . write . mint ( args ) ;
98
101
}
99
102
100
- async transfer ( params : { to : Address ; value : Uint256 } ) : Promise < Hash > {
101
- const args = [ params . to , params . value ] ;
103
+ async transfer ( params : { to : Address ; value : number } ) : Promise < Hash > {
104
+ const args = [ params . to , removeDecimals ( params . value ) ] ;
102
105
103
106
try {
104
107
await this . contract . simulate . transfer ( args ) ;
@@ -109,8 +112,8 @@ export class JPYC implements IJPYC {
109
112
return await this . contract . write . transfer ( args ) ;
110
113
}
111
114
112
- async transferFrom ( params : { from : Address ; to : Address ; value : Uint256 } ) : Promise < Hash > {
113
- const args = [ params . from , params . to , params . value ] ;
115
+ async transferFrom ( params : { from : Address ; to : Address ; value : number } ) : Promise < Hash > {
116
+ const args = [ params . from , params . to , removeDecimals ( params . value ) ] ;
114
117
115
118
try {
116
119
await this . contract . simulate . transferFrom ( args ) ;
@@ -124,7 +127,7 @@ export class JPYC implements IJPYC {
124
127
async transferWithAuthorization ( params : {
125
128
from : Address ;
126
129
to : Address ;
127
- value : Uint256 ;
130
+ value : number ;
128
131
validAfter : Uint256 ;
129
132
validBefore : Uint256 ;
130
133
nonce : Bytes32 ;
@@ -135,7 +138,7 @@ export class JPYC implements IJPYC {
135
138
const args = [
136
139
params . from ,
137
140
params . to ,
138
- params . value ,
141
+ removeDecimals ( params . value ) ,
139
142
params . validAfter ,
140
143
params . validBefore ,
141
144
params . nonce ,
@@ -156,7 +159,7 @@ export class JPYC implements IJPYC {
156
159
async receiveWithAuthorization ( params : {
157
160
from : Address ;
158
161
to : Address ;
159
- value : Uint256 ;
162
+ value : number ;
160
163
validAfter : Uint256 ;
161
164
validBefore : Uint256 ;
162
165
nonce : Bytes32 ;
@@ -167,7 +170,7 @@ export class JPYC implements IJPYC {
167
170
const args = [
168
171
params . from ,
169
172
params . to ,
170
- params . value ,
173
+ removeDecimals ( params . value ) ,
171
174
params . validAfter ,
172
175
params . validBefore ,
173
176
params . nonce ,
@@ -203,8 +206,8 @@ export class JPYC implements IJPYC {
203
206
return await this . contract . write . cancelAuthorization ( args ) ;
204
207
}
205
208
206
- async approve ( params : { spender : Address ; value : Uint256 } ) : Promise < Hash > {
207
- const args = [ params . spender , params . value ] ;
209
+ async approve ( params : { spender : Address ; value : number } ) : Promise < Hash > {
210
+ const args = [ params . spender , removeDecimals ( params . value ) ] ;
208
211
209
212
try {
210
213
await this . contract . simulate . approve ( args ) ;
@@ -215,8 +218,8 @@ export class JPYC implements IJPYC {
215
218
return await this . contract . write . approve ( args ) ;
216
219
}
217
220
218
- async increaseAllowance ( params : { spender : Address ; increment : Uint256 } ) : Promise < Hash > {
219
- const args = [ params . spender , params . increment ] ;
221
+ async increaseAllowance ( params : { spender : Address ; increment : number } ) : Promise < Hash > {
222
+ const args = [ params . spender , removeDecimals ( params . increment ) ] ;
220
223
221
224
try {
222
225
await this . contract . simulate . increaseAllowance ( args ) ;
@@ -227,8 +230,8 @@ export class JPYC implements IJPYC {
227
230
return await this . contract . write . increaseAllowance ( args ) ;
228
231
}
229
232
230
- async decreaseAllowance ( params : { spender : Address ; decrement : Uint256 } ) : Promise < Hash > {
231
- const args = [ params . spender , params . decrement ] ;
233
+ async decreaseAllowance ( params : { spender : Address ; decrement : number } ) : Promise < Hash > {
234
+ const args = [ params . spender , removeDecimals ( params . decrement ) ] ;
232
235
233
236
try {
234
237
await this . contract . simulate . decreaseAllowance ( args ) ;
@@ -242,7 +245,7 @@ export class JPYC implements IJPYC {
242
245
async permit ( params : {
243
246
owner : Address ;
244
247
spender : Address ;
245
- value : Uint256 ;
248
+ value : number ;
246
249
deadline : Uint256 ;
247
250
v : Uint8 ;
248
251
r : Bytes32 ;
@@ -251,7 +254,7 @@ export class JPYC implements IJPYC {
251
254
const args = [
252
255
params . owner ,
253
256
params . spender ,
254
- params . value ,
257
+ removeDecimals ( params . value ) ,
255
258
params . deadline ,
256
259
params . v ,
257
260
params . r ,
0 commit comments