-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy path2-gold-asc.js
75 lines (65 loc) · 2.35 KB
/
2-gold-asc.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, signTransactions } = require("@algo-builder/algob");
const { types, getSuggestedParams } = require("@algo-builder/web");
const { mkParam, tryExecuteTx } = require("./transfer/common");
const { makeAssetTransferTxnWithSuggestedParams } = require("algosdk");
async function run(runtimeEnv, deployer) {
const masterAccount = deployer.accountsByName.get("master-account");
const goldOwner = deployer.accountsByName.get("alice");
await tryExecuteTx(
deployer,
mkParam(masterAccount, goldOwner.addr, 200e6, { note: "funding account" })
);
// save Smart Signature by name & fund the account
const ascInfoContract = await deployer
.mkContractLsig("Gold_C_Lsig", "2-gold-contract-asc.teal", {})
.catch((error) => {
throw error;
});
console.log(ascInfoContract);
// funding with 1 Algo
await deployer
.fundLsig("Gold_C_Lsig", { funder: goldOwner, fundingMicroAlgo: 1e6 }, {})
.catch((error) => {
throw error;
});
const ascInfoAlgoDelegated = await deployer
.mkDelegatedLsig("Gold_D_Lsig", "3-gold-delegated-asc.teal", goldOwner)
.catch((error) => {
throw error;
});
const ascInfoGoldDelegated = await deployer
.mkDelegatedLsig("Gold_d_asa_lsig", "4-gold-asa.teal", goldOwner)
.catch((error) => {
throw error;
});
console.log(ascInfoAlgoDelegated);
console.log(ascInfoGoldDelegated);
/* Contract opt-in for ASA gold + fund contract with ASA gold */
const lsig = await deployer.getLsig("Gold_C_Lsig");
const goldAsset = deployer.asa.get("gold");
const goldAssetID = goldAsset.assetIndex;
await deployer.optInLsigToASA(goldAssetID, lsig, { totalFee: 1000 }).catch((error) => {
throw error;
});
console.log("Balance: ", await balanceOf(deployer, lsig.address(), goldAssetID));
console.log(`Funding contract ${lsig.address()} with ASA gold`);
const tx = makeAssetTransferTxnWithSuggestedParams(
goldOwner.addr,
lsig.address(),
undefined,
undefined,
1e5,
undefined,
goldAssetID,
await getSuggestedParams(deployer.algodClient)
);
const sign = {
sign: types.SignType.SecretKey,
fromAccount: goldOwner,
};
await tryExecuteTx(deployer, [{ transaction: tx, sign: sign }]);
await balanceOf(deployer, lsig.address(), goldAssetID);
// To get raw signed transaction you may use `signTransactions` function
const _rawSign = signTransactions([{ transaction: tx, sign: sign }]);
}
module.exports = { default: run };