diff --git a/src/packages/gasSponsor.ts b/src/packages/gasSponsor.ts index 48c1145..937ff81 100644 --- a/src/packages/gasSponsor.ts +++ b/src/packages/gasSponsor.ts @@ -4,8 +4,9 @@ import { ClaimRewardParams, ClaimRewardRespone, CreateGiftRespone, GasSponsorCre import { GiftCore } from "./giftCore"; export class GasSponsor extends GiftCore { - constructor(){ - super(CONTRACT_NAME.GAS_SPONSOR_CONTRACT_ADDRESS) + constructor(privateKey?: string){ + super(CONTRACT_NAME.GAS_SPONSOR_CONTRACT_ADDRESS, privateKey) + } async createGifts(params: GasSponsorCreateGiftsParams): Promise{ @@ -20,7 +21,7 @@ export class GasSponsor extends GiftCore { value: isNative ? BigInt(inputConfig.totalReward) : BigInt(0) }); - const { transactionHash ,events } = await response.wait() + const { transactionHash , events } = await response.wait() if(isNative){ return { diff --git a/src/packages/giftCore.ts b/src/packages/giftCore.ts index 763bc7b..5cc650b 100644 --- a/src/packages/giftCore.ts +++ b/src/packages/giftCore.ts @@ -1,18 +1,19 @@ import type { Wallet } from "@wallet/core" import { Contract, ethers, providers, Wallet as EthersWallet } from "ethers" -import { CHAIN_ID, CONTRACT_NAME, GIFT_ABI, GIFT_CONTRACT, PRIVATE_KEY, RPC_URL } from "../constants" +import { CHAIN_ID, CONTRACT_NAME, GIFT_ABI, GIFT_CONTRACT, RPC_URL } from "../constants" export class GiftCore{ provider: ethers.providers.JsonRpcProvider contract: Contract - signer: ethers.Wallet + admin: ethers.Wallet contractAddress: string + static instance: GiftCore; - constructor(contractName: CONTRACT_NAME){ + constructor(contractName: CONTRACT_NAME, privateKey?: string){ this.contractAddress = GIFT_CONTRACT[contractName] this.provider = new providers.JsonRpcProvider(RPC_URL, CHAIN_ID); - this.signer =new EthersWallet(PRIVATE_KEY, this.provider) - this.contract = new Contract(GIFT_CONTRACT[contractName], GIFT_ABI[contractName], this.signer) + this.admin =new EthersWallet(privateKey as string, this.provider) + this.contract = new Contract(GIFT_CONTRACT[contractName], GIFT_ABI[contractName], this.admin) } async getNonceAccount(address: string): Promise{ diff --git a/src/packages/giftFactoy.ts b/src/packages/giftFactoy.ts index 9913a1c..f20d2d8 100644 --- a/src/packages/giftFactoy.ts +++ b/src/packages/giftFactoy.ts @@ -8,9 +8,9 @@ import { GiftCore } from "./giftCore"; export class GiftFactory extends GiftCore{ sponsorGasContract: GasSponsor - constructor(){ - super(CONTRACT_NAME.COIN98_GIFT_FACTORY_CONTRACT_ADDRESS) - this.sponsorGasContract = new GasSponsor() + constructor(privateKey: string){ + super(CONTRACT_NAME.COIN98_GIFT_FACTORY_CONTRACT_ADDRESS, privateKey) + this.sponsorGasContract = new GasSponsor(privateKey) } async createGifts(params: CreateGiftsParams): Promise{ @@ -85,9 +85,9 @@ export class GiftFactory extends GiftCore{ async submitRewardRecipient(recipcient: string, giftContractAddress: string): Promise{ try { - const giftContract = new ethers.Contract(giftContractAddress , GIFT_ABI['COIN98_GIFT_CONTRACT_ADDRESS'], this.signer ) + const giftContract = new ethers.Contract(giftContractAddress , GIFT_ABI['COIN98_GIFT_CONTRACT_ADDRESS'], this.admin ) - const { hash } = await giftContract.connect(this.signer).submitRewardRecipient(recipcient,{ + const { hash } = await giftContract.connect(this.admin).submitRewardRecipient(recipcient,{ gasLimit: 650000 }) @@ -108,13 +108,13 @@ export class GiftFactory extends GiftCore{ } async setFee( params: SetFee ): Promise{ - const { tokenAddress = ethers.constants.AddressZero, isActivated = true, percentAmount = 0, feeRecipient = this.signer.address } = params + const { tokenAddress = ethers.constants.AddressZero, isActivated = true, percentAmount = 0, feeRecipient = this.admin.address } = params try { const unlockSetFee = await this.unlockFunction('setFee'); if(unlockSetFee){ - const nonce = await this.getNonceAccount(this.signer.address) - const response = await this.contract.connect(this.signer).setFee(tokenAddress, { + const nonce = await this.getNonceAccount(this.admin.address) + const response = await this.contract.connect(this.admin).setFee(tokenAddress, { isActivated, percentAmount: BigInt(percentAmount), feeRecipient: feeRecipient @@ -138,7 +138,7 @@ export class GiftFactory extends GiftCore{ const unlockAdmin = await this.unlockFunction('setAdmin'); if(unlockAdmin){ - const nonce = await this.getNonceAccount(this.signer.address) + const nonce = await this.getNonceAccount(this.admin.address) const response = await this.contract.setAdmin(address, true,{ gasLimit: 210000, @@ -166,8 +166,8 @@ export class GiftFactory extends GiftCore{ async getGiftConfig(giftContractAddress: string): Promise{ try { - const giftContract = new ethers.Contract(giftContractAddress , GIFT_ABI['COIN98_GIFT_CONTRACT_ADDRESS'], this.signer) - const giftConfig = await giftContract.connect(this.signer).getGiftConfig() + const giftContract = new ethers.Contract(giftContractAddress , GIFT_ABI['COIN98_GIFT_CONTRACT_ADDRESS'], this.admin) + const giftConfig = await giftContract.connect(this.admin).getGiftConfig() return { baseMultiplier: Number(giftConfig.baseMultiplier.toString()), @@ -188,8 +188,8 @@ export class GiftFactory extends GiftCore{ async getInsertedSlot(params: GetInsertedSlotParams): Promise{ const { giftContractAddress, recipientAddress } = params try { - const giftContract = new ethers.Contract(giftContractAddress , GIFT_ABI['COIN98_GIFT_CONTRACT_ADDRESS'], this.signer) - const slotConfig = await giftContract.connect(this.signer).getInsertedSlot(recipientAddress) + const giftContract = new ethers.Contract(giftContractAddress , GIFT_ABI['COIN98_GIFT_CONTRACT_ADDRESS'], this.admin) + const slotConfig = await giftContract.connect(this.admin).getInsertedSlot(recipientAddress) return { isClaimed: slotConfig.isClaimed, @@ -204,7 +204,7 @@ export class GiftFactory extends GiftCore{ async unlockFunction(functionName: string): Promise{ try { - const nonce = await this.getNonceAccount(this.signer.address) + const nonce = await this.getNonceAccount(this.admin.address) const response = await this.contract.unlock(this.contract.interface.getSighash(functionName),{ gasLimit: 210000,