tempo.ts 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ox/TokenRole.d.ts +1 -1
- package/dist/ox/TokenRole.d.ts.map +1 -1
- package/dist/viem/abis.d.ts +763 -1454
- package/dist/viem/abis.d.ts.map +1 -1
- package/dist/viem/abis.js +486 -1224
- package/dist/viem/abis.js.map +1 -1
- package/dist/viem/actions/amm.d.ts +630 -715
- package/dist/viem/actions/amm.d.ts.map +1 -1
- package/dist/viem/actions/fee.d.ts +65 -418
- package/dist/viem/actions/fee.d.ts.map +1 -1
- package/dist/viem/actions/policy.d.ts +365 -593
- package/dist/viem/actions/policy.d.ts.map +1 -1
- package/dist/viem/actions/policy.js +9 -4
- package/dist/viem/actions/policy.js.map +1 -1
- package/dist/viem/actions/token.d.ts +4768 -7384
- package/dist/viem/actions/token.d.ts.map +1 -1
- package/dist/viem/actions/token.js +57 -4
- package/dist/viem/actions/token.js.map +1 -1
- package/dist/viem/decorator.d.ts +23 -0
- package/dist/viem/decorator.d.ts.map +1 -1
- package/dist/viem/decorator.js +1 -0
- package/dist/viem/decorator.js.map +1 -1
- package/dist/viem/index.d.ts +1 -0
- package/dist/viem/index.d.ts.map +1 -1
- package/dist/viem/index.js +1 -0
- package/dist/viem/index.js.map +1 -1
- package/package.json +2 -2
- package/src/ox/TokenRole.test.ts +0 -4
- package/src/ox/TokenRole.ts +1 -1
- package/src/ox/TransactionEnvelopeFeeToken.test.ts +6 -102
- package/src/viem/abis.ts +495 -1234
- package/src/viem/actions/policy.ts +9 -4
- package/src/viem/actions/token.test.ts +190 -0
- package/src/viem/actions/token.ts +82 -4
- package/src/viem/client.test.ts +1 -0
- package/src/viem/decorator.bench-d.ts +1 -1
- package/src/viem/decorator.ts +26 -0
- package/src/viem/index.ts +1 -0
|
@@ -162,13 +162,18 @@ export namespace create {
|
|
|
162
162
|
export function call(args: Args) {
|
|
163
163
|
const { admin, type, addresses } = args
|
|
164
164
|
const callArgs = addresses
|
|
165
|
-
? (
|
|
166
|
-
|
|
165
|
+
? ({
|
|
166
|
+
functionName: 'createPolicyWithAccounts',
|
|
167
|
+
args: [admin, policyTypeMap[type], addresses],
|
|
168
|
+
} as const)
|
|
169
|
+
: ({
|
|
170
|
+
functionName: 'createPolicy',
|
|
171
|
+
args: [admin, policyTypeMap[type]],
|
|
172
|
+
} as const)
|
|
167
173
|
return defineCall({
|
|
168
174
|
address: tip403RegistryAddress,
|
|
169
175
|
abi: tip403RegistryAbi,
|
|
170
|
-
|
|
171
|
-
args: callArgs,
|
|
176
|
+
...callArgs,
|
|
172
177
|
})
|
|
173
178
|
}
|
|
174
179
|
|
|
@@ -1087,6 +1087,196 @@ describe('unpause', () => {
|
|
|
1087
1087
|
|
|
1088
1088
|
describe.todo('setTokenSupplyCap')
|
|
1089
1089
|
|
|
1090
|
+
describe('hasRole', () => {
|
|
1091
|
+
test('default', async () => {
|
|
1092
|
+
// Create a new token where we're the admin
|
|
1093
|
+
const { token: address } = await actions.token.createSync(client, {
|
|
1094
|
+
currency: 'USD',
|
|
1095
|
+
name: 'HasRole Test Token',
|
|
1096
|
+
symbol: 'HRTEST',
|
|
1097
|
+
})
|
|
1098
|
+
|
|
1099
|
+
// Client account should have defaultAdmin role on the new token
|
|
1100
|
+
const hasDefaultAdminRole = await actions.token.hasRole(client, {
|
|
1101
|
+
token: address,
|
|
1102
|
+
role: 'defaultAdmin',
|
|
1103
|
+
})
|
|
1104
|
+
expect(hasDefaultAdminRole).toBe(true)
|
|
1105
|
+
|
|
1106
|
+
// Client account should not have issuer role initially on the new token
|
|
1107
|
+
const hasIssuerRole = await actions.token.hasRole(client, {
|
|
1108
|
+
token: address,
|
|
1109
|
+
role: 'issuer',
|
|
1110
|
+
})
|
|
1111
|
+
expect(hasIssuerRole).toBe(false)
|
|
1112
|
+
|
|
1113
|
+
// Grant issuer role
|
|
1114
|
+
await actions.token.grantRolesSync(client, {
|
|
1115
|
+
token: address,
|
|
1116
|
+
roles: ['issuer'],
|
|
1117
|
+
to: client.account.address,
|
|
1118
|
+
})
|
|
1119
|
+
|
|
1120
|
+
// Now should have issuer role
|
|
1121
|
+
const hasIssuerRoleAfterGrant = await actions.token.hasRole(client, {
|
|
1122
|
+
token: address,
|
|
1123
|
+
role: 'issuer',
|
|
1124
|
+
})
|
|
1125
|
+
expect(hasIssuerRoleAfterGrant).toBe(true)
|
|
1126
|
+
})
|
|
1127
|
+
|
|
1128
|
+
test('behavior: check other account', async () => {
|
|
1129
|
+
// Create a new token
|
|
1130
|
+
const { token: address } = await actions.token.createSync(client, {
|
|
1131
|
+
currency: 'USD',
|
|
1132
|
+
name: 'HasRole Other Account',
|
|
1133
|
+
symbol: 'HROAC',
|
|
1134
|
+
})
|
|
1135
|
+
|
|
1136
|
+
// Account2 should not have issuer role
|
|
1137
|
+
const hasIssuerBefore = await actions.token.hasRole(client, {
|
|
1138
|
+
token: address,
|
|
1139
|
+
account: account2.address,
|
|
1140
|
+
role: 'issuer',
|
|
1141
|
+
})
|
|
1142
|
+
expect(hasIssuerBefore).toBe(false)
|
|
1143
|
+
|
|
1144
|
+
// Grant issuer role to account2
|
|
1145
|
+
await actions.token.grantRolesSync(client, {
|
|
1146
|
+
token: address,
|
|
1147
|
+
roles: ['issuer'],
|
|
1148
|
+
to: account2.address,
|
|
1149
|
+
})
|
|
1150
|
+
|
|
1151
|
+
// Account2 should now have issuer role
|
|
1152
|
+
const hasIssuerAfter = await actions.token.hasRole(client, {
|
|
1153
|
+
token: address,
|
|
1154
|
+
account: account2.address,
|
|
1155
|
+
role: 'issuer',
|
|
1156
|
+
})
|
|
1157
|
+
expect(hasIssuerAfter).toBe(true)
|
|
1158
|
+
|
|
1159
|
+
// Account3 should still not have issuer role
|
|
1160
|
+
const account3HasIssuer = await actions.token.hasRole(client, {
|
|
1161
|
+
token: address,
|
|
1162
|
+
account: account3.address,
|
|
1163
|
+
role: 'issuer',
|
|
1164
|
+
})
|
|
1165
|
+
expect(account3HasIssuer).toBe(false)
|
|
1166
|
+
})
|
|
1167
|
+
|
|
1168
|
+
test('behavior: multiple roles', async () => {
|
|
1169
|
+
// Create a new token
|
|
1170
|
+
const { token: address } = await actions.token.createSync(client, {
|
|
1171
|
+
currency: 'USD',
|
|
1172
|
+
name: 'HasRole Multiple',
|
|
1173
|
+
symbol: 'HRMULTI',
|
|
1174
|
+
})
|
|
1175
|
+
|
|
1176
|
+
// Grant multiple roles to account2
|
|
1177
|
+
await actions.token.grantRolesSync(client, {
|
|
1178
|
+
token: address,
|
|
1179
|
+
roles: ['issuer', 'pause'],
|
|
1180
|
+
to: account2.address,
|
|
1181
|
+
})
|
|
1182
|
+
|
|
1183
|
+
// Check issuer role
|
|
1184
|
+
const hasIssuer = await actions.token.hasRole(client, {
|
|
1185
|
+
token: address,
|
|
1186
|
+
account: account2.address,
|
|
1187
|
+
role: 'issuer',
|
|
1188
|
+
})
|
|
1189
|
+
expect(hasIssuer).toBe(true)
|
|
1190
|
+
|
|
1191
|
+
// Check pause role
|
|
1192
|
+
const hasPause = await actions.token.hasRole(client, {
|
|
1193
|
+
token: address,
|
|
1194
|
+
account: account2.address,
|
|
1195
|
+
role: 'pause',
|
|
1196
|
+
})
|
|
1197
|
+
expect(hasPause).toBe(true)
|
|
1198
|
+
|
|
1199
|
+
// Check unpause role (not granted)
|
|
1200
|
+
const hasUnpause = await actions.token.hasRole(client, {
|
|
1201
|
+
token: address,
|
|
1202
|
+
account: account2.address,
|
|
1203
|
+
role: 'unpause',
|
|
1204
|
+
})
|
|
1205
|
+
expect(hasUnpause).toBe(false)
|
|
1206
|
+
})
|
|
1207
|
+
|
|
1208
|
+
test('behavior: after revoke', async () => {
|
|
1209
|
+
// Create a new token
|
|
1210
|
+
const { token: address } = await actions.token.createSync(client, {
|
|
1211
|
+
currency: 'USD',
|
|
1212
|
+
name: 'HasRole Revoke',
|
|
1213
|
+
symbol: 'HRREV',
|
|
1214
|
+
})
|
|
1215
|
+
|
|
1216
|
+
// Grant issuer role to account2
|
|
1217
|
+
await actions.token.grantRolesSync(client, {
|
|
1218
|
+
token: address,
|
|
1219
|
+
roles: ['issuer'],
|
|
1220
|
+
to: account2.address,
|
|
1221
|
+
})
|
|
1222
|
+
|
|
1223
|
+
// Verify has role
|
|
1224
|
+
const hasRoleBefore = await actions.token.hasRole(client, {
|
|
1225
|
+
token: address,
|
|
1226
|
+
account: account2.address,
|
|
1227
|
+
role: 'issuer',
|
|
1228
|
+
})
|
|
1229
|
+
expect(hasRoleBefore).toBe(true)
|
|
1230
|
+
|
|
1231
|
+
// Revoke the role
|
|
1232
|
+
await actions.token.revokeRolesSync(client, {
|
|
1233
|
+
token: address,
|
|
1234
|
+
roles: ['issuer'],
|
|
1235
|
+
from: account2.address,
|
|
1236
|
+
})
|
|
1237
|
+
|
|
1238
|
+
// Verify no longer has role
|
|
1239
|
+
const hasRoleAfter = await actions.token.hasRole(client, {
|
|
1240
|
+
token: address,
|
|
1241
|
+
account: account2.address,
|
|
1242
|
+
role: 'issuer',
|
|
1243
|
+
})
|
|
1244
|
+
expect(hasRoleAfter).toBe(false)
|
|
1245
|
+
})
|
|
1246
|
+
|
|
1247
|
+
test('behavior: with token ID', async () => {
|
|
1248
|
+
// Create a new token
|
|
1249
|
+
const { token: address, tokenId } = await actions.token.createSync(client, {
|
|
1250
|
+
currency: 'USD',
|
|
1251
|
+
name: 'HasRole Token ID',
|
|
1252
|
+
symbol: 'HRTID',
|
|
1253
|
+
})
|
|
1254
|
+
|
|
1255
|
+
// Grant issuer role
|
|
1256
|
+
await actions.token.grantRolesSync(client, {
|
|
1257
|
+
token: tokenId,
|
|
1258
|
+
roles: ['issuer'],
|
|
1259
|
+
to: account2.address,
|
|
1260
|
+
})
|
|
1261
|
+
|
|
1262
|
+
// Check using token ID
|
|
1263
|
+
const hasRole = await actions.token.hasRole(client, {
|
|
1264
|
+
token: tokenId,
|
|
1265
|
+
account: account2.address,
|
|
1266
|
+
role: 'issuer',
|
|
1267
|
+
})
|
|
1268
|
+
expect(hasRole).toBe(true)
|
|
1269
|
+
|
|
1270
|
+
// Verify same result with address
|
|
1271
|
+
const hasRoleWithAddress = await actions.token.hasRole(client, {
|
|
1272
|
+
token: address,
|
|
1273
|
+
account: account2.address,
|
|
1274
|
+
role: 'issuer',
|
|
1275
|
+
})
|
|
1276
|
+
expect(hasRoleWithAddress).toBe(true)
|
|
1277
|
+
})
|
|
1278
|
+
})
|
|
1279
|
+
|
|
1090
1280
|
describe('grantRoles', () => {
|
|
1091
1281
|
test('default', async () => {
|
|
1092
1282
|
// Create a new token where we're the admin
|
|
@@ -1081,12 +1081,12 @@ export async function getAllowance<
|
|
|
1081
1081
|
client: Client<Transport, chain, account>,
|
|
1082
1082
|
parameters: getAllowance.Parameters<account>,
|
|
1083
1083
|
): Promise<getAllowance.ReturnValue> {
|
|
1084
|
-
const { account = client.account
|
|
1084
|
+
const { account = client.account } = parameters
|
|
1085
1085
|
const address = account ? parseAccount(account).address : undefined
|
|
1086
1086
|
if (!address) throw new Error('account is required.')
|
|
1087
1087
|
return readContract(client, {
|
|
1088
|
-
...
|
|
1089
|
-
...getAllowance.call({ account: address
|
|
1088
|
+
...parameters,
|
|
1089
|
+
...getAllowance.call({ ...parameters, account: address }),
|
|
1090
1090
|
})
|
|
1091
1091
|
}
|
|
1092
1092
|
|
|
@@ -1333,6 +1333,84 @@ export declare namespace getMetadata {
|
|
|
1333
1333
|
}>
|
|
1334
1334
|
}
|
|
1335
1335
|
|
|
1336
|
+
/**
|
|
1337
|
+
* Checks if an account has a specific role for a TIP20 token.
|
|
1338
|
+
*
|
|
1339
|
+
* @example
|
|
1340
|
+
* ```ts
|
|
1341
|
+
* import { createClient, http } from 'viem'
|
|
1342
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1343
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1344
|
+
*
|
|
1345
|
+
* const client = createClient({
|
|
1346
|
+
* chain: tempo,
|
|
1347
|
+
* transport: http(),
|
|
1348
|
+
* })
|
|
1349
|
+
*
|
|
1350
|
+
* const hasRole = await actions.token.hasRole(client, {
|
|
1351
|
+
* account: '0x...',
|
|
1352
|
+
* role: 'issuer',
|
|
1353
|
+
* token: '0x...',
|
|
1354
|
+
* })
|
|
1355
|
+
* ```
|
|
1356
|
+
*
|
|
1357
|
+
* @param client - Client.
|
|
1358
|
+
* @param parameters - Parameters.
|
|
1359
|
+
* @returns Whether the account has the role.
|
|
1360
|
+
*/
|
|
1361
|
+
export async function hasRole<
|
|
1362
|
+
chain extends Chain | undefined,
|
|
1363
|
+
account extends Account | undefined,
|
|
1364
|
+
>(
|
|
1365
|
+
client: Client<Transport, chain, account>,
|
|
1366
|
+
parameters: hasRole.Parameters<account>,
|
|
1367
|
+
): Promise<hasRole.ReturnValue> {
|
|
1368
|
+
const { account = client.account } = parameters
|
|
1369
|
+
const address = account ? parseAccount(account).address : undefined
|
|
1370
|
+
if (!address) throw new Error('account is required.')
|
|
1371
|
+
return readContract(client, {
|
|
1372
|
+
...parameters,
|
|
1373
|
+
...hasRole.call({ ...parameters, account: address }),
|
|
1374
|
+
})
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
export namespace hasRole {
|
|
1378
|
+
export type Parameters<
|
|
1379
|
+
account extends Account | undefined = Account | undefined,
|
|
1380
|
+
> = ReadParameters & Omit<Args, 'account'> & GetAccountParameter<account>
|
|
1381
|
+
|
|
1382
|
+
export type Args = {
|
|
1383
|
+
/** Account address to check. */
|
|
1384
|
+
account: Address
|
|
1385
|
+
/** Role to check. */
|
|
1386
|
+
role: TokenRole.TokenRole
|
|
1387
|
+
/** Address or ID of the TIP20 token. */
|
|
1388
|
+
token: TokenId.TokenIdOrAddress
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
export type ReturnValue = ReadContractReturnType<
|
|
1392
|
+
typeof tip20Abi,
|
|
1393
|
+
'hasRole',
|
|
1394
|
+
never
|
|
1395
|
+
>
|
|
1396
|
+
|
|
1397
|
+
/**
|
|
1398
|
+
* Defines a call to the `hasRole` function.
|
|
1399
|
+
*
|
|
1400
|
+
* @param args - Arguments.
|
|
1401
|
+
* @returns The call.
|
|
1402
|
+
*/
|
|
1403
|
+
export function call(args: Args) {
|
|
1404
|
+
const { account, role, token } = args
|
|
1405
|
+
return defineCall({
|
|
1406
|
+
address: TokenId.toAddress(token),
|
|
1407
|
+
abi: tip20Abi,
|
|
1408
|
+
functionName: 'hasRole',
|
|
1409
|
+
args: [account, TokenRole.serialize(role)],
|
|
1410
|
+
})
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1336
1414
|
/**
|
|
1337
1415
|
* Grants a role for a TIP20 token.
|
|
1338
1416
|
*
|
|
@@ -1352,7 +1430,7 @@ export declare namespace getMetadata {
|
|
|
1352
1430
|
* const result = await actions.token.grantRoles(client, {
|
|
1353
1431
|
* token: '0x...',
|
|
1354
1432
|
* to: '0x...',
|
|
1355
|
-
* roles: ['
|
|
1433
|
+
* roles: ['issuer'],
|
|
1356
1434
|
* })
|
|
1357
1435
|
* ```
|
|
1358
1436
|
*
|
package/src/viem/client.test.ts
CHANGED
package/src/viem/decorator.ts
CHANGED
|
@@ -1099,6 +1099,31 @@ export type Decorator<
|
|
|
1099
1099
|
getMetadata: (
|
|
1100
1100
|
parameters: tokenActions.getMetadata.Parameters,
|
|
1101
1101
|
) => Promise<tokenActions.getMetadata.ReturnValue>
|
|
1102
|
+
/**
|
|
1103
|
+
* Checks if an account has a specific role for a TIP20 token.
|
|
1104
|
+
*
|
|
1105
|
+
* @example
|
|
1106
|
+
* ```ts
|
|
1107
|
+
* import { createTempoClient } from 'tempo.ts/viem'
|
|
1108
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1109
|
+
*
|
|
1110
|
+
* const client = createTempoClient({
|
|
1111
|
+
* account: privateKeyToAccount('0x...')
|
|
1112
|
+
* })
|
|
1113
|
+
*
|
|
1114
|
+
* const hasRole = await client.token.hasRole({
|
|
1115
|
+
* token: '0x...',
|
|
1116
|
+
* role: 'issuer',
|
|
1117
|
+
* })
|
|
1118
|
+
* ```
|
|
1119
|
+
*
|
|
1120
|
+
* @param client - Client.
|
|
1121
|
+
* @param parameters - Parameters.
|
|
1122
|
+
* @returns Whether the account has the role.
|
|
1123
|
+
*/
|
|
1124
|
+
hasRole: (
|
|
1125
|
+
parameters: tokenActions.hasRole.Parameters<account>,
|
|
1126
|
+
) => Promise<tokenActions.hasRole.ReturnValue>
|
|
1102
1127
|
/**
|
|
1103
1128
|
* Grants a role for a TIP20 token.
|
|
1104
1129
|
*
|
|
@@ -1866,6 +1891,7 @@ export function decorator() {
|
|
|
1866
1891
|
getBalance: (parameters) => tokenActions.getBalance(client, parameters),
|
|
1867
1892
|
getMetadata: (parameters) =>
|
|
1868
1893
|
tokenActions.getMetadata(client, parameters),
|
|
1894
|
+
hasRole: (parameters) => tokenActions.hasRole(client, parameters),
|
|
1869
1895
|
grantRoles: (parameters) => tokenActions.grantRoles(client, parameters),
|
|
1870
1896
|
grantRolesSync: (parameters) =>
|
|
1871
1897
|
tokenActions.grantRolesSync(client, parameters),
|