-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_farm.mjs
58 lines (50 loc) · 1.61 KB
/
deploy_farm.mjs
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
import * as backend from "./build/farm.main.mjs";
import { stdlib, deployStandardContract, configureUsersAndTokens } from "./common.mjs";
import { BigNumber } from "ethers";
import log from "loglevel";
export async function init(accountsNumber) {
const creatorAcc = await stdlib.newTestAccount(stdlib.parseCurrency(100));
const userAccs = await stdlib.newTestAccounts(accountsNumber, stdlib.parseCurrency(10));
log.trace("Accounts created and funded with ALGO");
const stakeToken = await stdlib.launchToken(creatorAcc, "Staky", "STAKE");
const rewardToken = await stdlib.launchToken(creatorAcc, "Rewardy", "REWARD");
log.trace("Staking and reward tokens minted");
await configureUsersAndTokens([creatorAcc, ...userAccs], [stakeToken, rewardToken]);
const initalStakyBalance = BigNumber.from(1000000);
for (const acc of userAccs) {
await stdlib.transfer(creatorAcc, acc, initalStakyBalance, stakeToken.id);
}
log.trace("Stakers received STAKE token");
return {
creatorAcc,
userAccs,
tokens: {
stakeToken,
rewardToken,
},
};
}
export async function deploy(
creatorAcc,
userAccs,
stakeToken,
rewardToken,
beginBlock = 0,
blocksToRun = 1000,
rewardPerBlock = 1000
) {
const creatorCtc = creatorAcc.contract(backend);
const contractId = await deployStandardContract(creatorCtc, {
stakeToken: stakeToken.id,
rewardToken: rewardToken.id,
beginBlock,
endBlock: beginBlock + blocksToRun,
rewardPerBlock,
});
const userCtcs = userAccs.map((acc) => acc.contract(backend, contractId));
return {
contractId,
creatorCtc,
userCtcs,
};
}