-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathopt-out.js
59 lines (49 loc) · 1.92 KB
/
opt-out.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
const { balanceOf } = require("@algo-builder/algob");
const { types } = require("@algo-builder/web");
const { issue } = require("../admin/issue");
const { fundAccount, tryExecuteTx } = require("../common/common");
/**
* To opt-out of the token, do an asset transfer transaction with
* closeRemainderTo == token creator address (creator == reserve in this case)
* @param {*} deployer algobDeployer
* @param {*} account account to opt-out of the token from
*/
async function optOut(deployer, account) {
const tesla = deployer.asa.get("tesla");
/*
* NOTE: User can only optOut asset to asset-creator account. If reserve account
* is different than creator, then creator will need to send these assets
* to reserve account (after user has opted out).
*/
const optOutParams = [
{
type: types.TransactionType.TransferAsset,
sign: types.SignType.SecretKey,
fromAccount: account,
toAccountAddr: account.addr,
assetID: tesla.assetIndex,
amount: 0,
payFlags: { totalFee: 1000, closeRemainderTo: tesla.creator },
},
];
console.log(`* Opting out [${account.name}:${account.addr}] from token 'tesla' *`);
await tryExecuteTx(deployer, optOutParams);
}
async function run(runtimeEnv, deployer) {
const elon = deployer.accountsByName.get("elon-musk");
const tesla = deployer.asa.get("tesla");
// fund elon
await fundAccount(deployer, elon);
// opt in elon to tesla first
await deployer.optInAccountToASA("tesla", elon.name, {});
// in scripts flow we kill the tesla token before executing opt-out,
// uncomment if running it in another sequence
// first issue few tokens to elon
// await issue(deployer, elon.addr, 15); // issue(mint) 15 tokens to elon from reserve
/*
* Use below function to opt-out elon from token tesla
*/
await optOut(deployer, elon);
console.log("Balance: ", await balanceOf(deployer, elon.addr, tesla.assetIndex)); // prints nothing
}
module.exports = { default: run, optOut: optOut };