Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions bot/modules/starknet.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import "dotenv/config";

import { Provider, Contract, Account, cairo, CallData } from "starknet";
import { num } from "starknet";

// Function to encode domain parts
const useEncoded = (str) => {
if (!str) return num.toBigInt(0);
const encoded = Buffer.from(str.toLowerCase())
.reduce((acc, byte) => acc + byte.toString(16).padStart(2, "0"), "0x");
return num.toBigInt(encoded);
};

//initialize Provider
const provider = new Provider({
nodeUrl: process.env.RPC_URL,
Expand Down Expand Up @@ -59,10 +69,27 @@ const mintToUser = async (calldata) => {

const getAddressFromDomain = async (domainName) => {
try {
const res = await provider.getAddressFromStarkName(domainName);
return res;
if (domainName.endsWith('.stark')) {
const res = await provider.getAddressFromStarkName(domainName);
return res;
} else if (domainName.endsWith('.brother')) {
const encodedDomain = domainName
.replace('.brother', '')
.split('.')
.map((part) => useEncoded(part).toString(10));

const domainDetails = await provider.callContract({
contractAddress: process.env.BROTHER_CONTRACT,
entrypoint: 'get_details_by_domain',
calldata: CallData.compile({ domain: encodedDomain }),
});

// The contract returns a DomainDetails struct where resolver is the second field
return domainDetails[1];
}
return null;
} catch (err) {
console.log(`Error fetching address for domain ${domainName}`);
console.log(`Error fetching address for domain ${domainName}:`, err);
return null;
}
};
Expand Down
4 changes: 2 additions & 2 deletions bot/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const checkForAddressFromTweet = (tweet) => {
};

export const checkDomainFromTweet = async (tweet) => {
const regex = /\.stark$/;
const regex = /\.(stark|brother)$/;

// split words and check
let wordIndex = 0;
Expand All @@ -32,7 +32,7 @@ export const checkDomainFromTweet = async (tweet) => {
let numOfWords = formattedText.split(" ").length;
while (wordIndex < numOfWords) {
const word = formattedText.split(" ")[wordIndex];
if (regex.test(word) && word !== ".stark") {
if (regex.test(word) && word !== ".stark" && word !== ".brother") {
currentAddress = await getAddressFromDomain(word?.toLowerCase());
}
wordIndex++;
Expand Down