-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathcommon.js
75 lines (68 loc) · 2.22 KB
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const { balanceOf } = require("@algo-builder/algob");
const { types } = require("@algo-builder/web");
exports.tryExecuteTx = async function (deployer, txnParams) {
try {
const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams];
return await deployer.executeTx(txnParameters);
} catch (e) {
console.error("Transaction Failed", e.response ? e.response.error : e);
throw e;
}
};
/**
* Fund accounts from master with 20 Algos
* @param {*} deployer algobDeployer
* @param {*} account or list of accounts to fund
*/
exports.fundAccount = async function (deployer, account) {
const master = deployer.accountsByName.get("master-account");
const params = [];
if (!(account instanceof Array)) {
account = [account];
}
for (const a of account) {
console.log(`* Funding Account: ${a.name} *`);
params.push({
type: types.TransactionType.TransferAlgo,
sign: types.SignType.SecretKey,
fromAccount: master,
toAccountAddr: a.addr,
amountMicroAlgos: 20e6,
payFlags: { totalFee: 1000, note: "funding account" },
});
}
try {
await deployer.executeTx(params);
} catch (e) {
console.error("Transaction Failed", e.response ? e.response.error.text : e);
}
};
exports.optInAccountToApp = async function (
deployer,
account,
appID,
payflags,
AppOptionalFlags
) {
try {
console.log(`* Opting In: ${account.name} to App with application index: ${appID} *`);
await deployer.optInAccountToApp(account, appID, payflags, AppOptionalFlags);
} catch (e) {
console.error("optInAccountToApp failed", e.response?.error); // probably app already optedIn
}
};
// returns totalSupply of asset (0 after deployment, will increase with each issuance transaction)
exports.totalSupply = async function (deployer, assetIndex) {
const asaDef = (await deployer.getAssetByID(assetIndex)).params;
const reserveAssetHoldingAmount = await balanceOf(deployer, asaDef.reserve, assetIndex);
return BigInt(asaDef.total) - BigInt(reserveAssetHoldingAmount);
};
function getClawbackParams(deployer) {
const tesla = deployer.asa.get("tesla");
const controllerInfo = deployer.getApp("Controller");
return {
TOKEN_ID: tesla.assetIndex,
CONTROLLER_APP_ID: controllerInfo.appID,
};
}
exports.getClawbackParams = getClawbackParams;