Skip to content

Commit 55987a8

Browse files
zmalatraxunknownunknown1
authored andcommitted
feat(deploy): add task to credit LINK from deployer to VRF subscription
1 parent d9384b6 commit 55987a8

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

contracts/hardhat.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import "hardhat-docgen";
1414
import "hardhat-contract-sizer";
1515
import "hardhat-tracer";
1616
require("./scripts/simulations/tasks");
17+
require("./scripts/creditLink");
1718

1819
dotenv.config();
1920

contracts/scripts/creditLink.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { deployments, getNamedAccounts, getChainId, ethers } from "hardhat";
2+
import { LinkTokenInterface, VRFSubscriptionManagerV2 } from "../typechain-types";
3+
import { task, types } from "hardhat/config";
4+
import { BigNumber } from "ethers";
5+
6+
enum HomeChains {
7+
ARBITRUM_ONE = 42161,
8+
ARBITRUM_GOERLI = 421613,
9+
}
10+
11+
// https://docs.chain.link/resources/link-token-contracts?parent=vrf#arbitrum
12+
const linkByChain = new Map<HomeChains, string>([
13+
[HomeChains.ARBITRUM_ONE, "0xf97f4df75117a78c1A5a0DBb814Af92458539FB4"],
14+
[HomeChains.ARBITRUM_GOERLI, "0xd14838A68E8AFBAdE5efb411d5871ea0011AFd28"],
15+
]);
16+
17+
const ONE_LINK_WEI = BigNumber.from(10).pow(18);
18+
19+
task("credit-link", "Credit LINK tokens to the current Chainlink VRF Subscription")
20+
.addParam("amount", "(in normal values, not wei!) The amount of LINK tokens to credit")
21+
.setAction(async (taskArgs, hre) => {
22+
const { deployments, getNamedAccounts, getChainId, ethers } = hre;
23+
const { AddressZero } = ethers.constants;
24+
const deployer = (await getNamedAccounts()).deployer ?? AddressZero;
25+
26+
const chainId = Number(await getChainId());
27+
if (!HomeChains[chainId]) {
28+
console.error(`Aborting: script is not compatible with ${chainId}`);
29+
return;
30+
} else {
31+
console.log("Crediting %d LINK to %s with deployer %s", HomeChains[chainId], deployer);
32+
}
33+
34+
const { amount } = taskArgs;
35+
const amountInWei = BigNumber.from(amount).mul(ONE_LINK_WEI);
36+
37+
// Retrieve LINK token contract from artifact to interact with it
38+
const linkTokenAddress = linkByChain.get(Number(await getChainId())) ?? AddressZero;
39+
const linkTokenArtifact = await hre.artifacts.readArtifact("LinkTokenInterface");
40+
const linkToken = (await ethers.getContractAtFromArtifact(
41+
linkTokenArtifact,
42+
linkTokenAddress
43+
)) as LinkTokenInterface;
44+
45+
const vrfSubscriptionManagerDeployment = await deployments.get("VRFSubscriptionManagerV2");
46+
const vrfSubscriptionManager = (await ethers.getContractAt(
47+
"VRFSubscriptionManagerV2",
48+
vrfSubscriptionManagerDeployment.address
49+
)) as VRFSubscriptionManagerV2;
50+
51+
// Transfer LINK from deployer to the Subscription Manager
52+
await linkToken.transfer(vrfSubscriptionManager.address, amountInWei);
53+
54+
// // Fund the subscription, sending `amount` LINK tokens
55+
await vrfSubscriptionManager.topUpSubscription(amountInWei);
56+
});

0 commit comments

Comments
 (0)