-
Notifications
You must be signed in to change notification settings - Fork 1
/
RUNE_airdrop.ts
78 lines (70 loc) · 1.94 KB
/
RUNE_airdrop.ts
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
76
77
78
import * as Bitcoin from "bitcoinjs-lib";
import ecc from "@bitcoinerlab/secp256k1";
import {
SEED,
STANDARD_RUNE_UTXO_VALUE,
TESTNET,
networkType,
} from "../../config/config";
import { IUtxo } from "../../utils/types";
import { RuneId, Runestone, none } from "runelib";
import initializeWallet from "../wallet/initializeWallet";
import { SeedWallet } from "../wallet/SeedWallet";
import app from "../..";
Bitcoin.initEccLib(ecc);
// Create dummy psbt for buyer offer
export const SameRuneTransferTx = (
addressList: Array<string>,
amount: number,
rune_id: string,
networkType: string,
runeUtxo: IUtxo
): string => {
// Initialize seed Wallet
const wallet: SeedWallet = initializeWallet(
networkType,
SEED,
app.locals.walletIndex
);
// Create psbt instance
const psbt = new Bitcoin.Psbt({
network:
networkType == TESTNET
? Bitcoin.networks.testnet
: Bitcoin.networks.bitcoin,
});
// Input all buyer Rune UTXOs for rune token
psbt.addInput({
hash: runeUtxo.txid,
index: runeUtxo.vout,
witnessUtxo: {
value: runeUtxo.value,
script: wallet.output,
},
tapInternalKey: Buffer.from(wallet.publicKey, "hex").subarray(1, 33),
});
// Create Runestone
const edicts: any = [];
edicts.push({
id: new RuneId(+rune_id.split(":")[0], +rune_id.split(":")[1]),
amount: 0,
output: addressList.length + 1,
});
const mintstone = new Runestone(edicts, none(), none(), none());
// Add output runestone
psbt.addOutput({
script: mintstone.encipher(),
value: 0,
});
// Add output for rune airdrop
for (let i = 0; i < addressList.length; i++) {
psbt.addOutput({
address: addressList[i],
value: STANDARD_RUNE_UTXO_VALUE,
});
}
// Sign psbt using admin wallet
const signedPsbt: Bitcoin.Psbt = wallet.signPsbt(psbt, wallet.ecPair);
// return Virtual Size of Runestone Transaction
return signedPsbt.extractTransaction(true).toHex();
};