From 5f620429f9f014f48eb67dea76e3b1fe04799e4d Mon Sep 17 00:00:00 2001 From: thanghoduc Date: Tue, 27 Aug 2024 16:26:25 +0700 Subject: [PATCH] chore: add receiver with oneids --- package.json | 2 +- src/constants/abi.ts | 637 +++++++++++++++++++++++++++---------- src/constants/contract.ts | 10 +- src/packages/giftFactoy.ts | 5 +- src/types/gifts.ts | 1 + 5 files changed, 481 insertions(+), 174 deletions(-) diff --git a/package.json b/package.json index 13faf48..69b6ccc 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "4.0.0", + "version": "4.1.0", "license": "MIT", "main": "src/index.ts", "types": "src/index.ts", diff --git a/src/constants/abi.ts b/src/constants/abi.ts index 63ed514..8b9ecca 100644 --- a/src/constants/abi.ts +++ b/src/constants/abi.ts @@ -619,172 +619,477 @@ export const COIN98_GIFT_FACTORY_ABI = [ ] export const COIN98_GIFT_V2_ABI = [ - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "recipient", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "slot", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "reward", - "type": "uint256" - } - ], - "name": "ClaimReward", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "recipient", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "slot", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "reward", - "type": "uint256" - } - ], - "name": "SubmitRewardRecipient", - "type": "event" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "address", - "name": "rewardToken", - "type": "address" - }, - { - "internalType": "uint256", - "name": "totalReward", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "totalSlots", - "type": "uint256" - }, - { - "internalType": "uint16", - "name": "randomPercent", - "type": "uint16" - }, - { - "internalType": "uint256", - "name": "baseMultiplier", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "endTimestamp", - "type": "uint256" - } - ], - "internalType": "struct ICoin98GiftV2.InputConfig", - "name": "inputConfig", - "type": "tuple" - } - ], - "name": "__Coin98GiftV2Init", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - } - ], - "name": "cancelGift", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "recipient", - "type": "address" - } - ], - "name": "claimReward", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address[]", - "name": "recipient", - "type": "address[]" - } - ], - "name": "submitRewardRecipients", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "withdraw", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - } - ], - "name": "withdrawRemainingReward", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - } -] + { + "inputs": [ + { + "internalType": "address", + "name": "randomizer", + "type": "address" + }, + { + "internalType": "address", + "name": "broadcaster", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "slot", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "reward", + "type": "uint256" + } + ], + "name": "ClaimReward", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "slot", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "reward", + "type": "uint256" + } + ], + "name": "SubmitRewardRecipient", + "type": "event" + }, + { + "stateMutability": "nonpayable", + "type": "fallback" + }, + { + "inputs": [], + "name": "PERCENT", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PROJECT_NAME", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PROJECT_VERSION", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "address", + "name": "rewardToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "totalReward", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalSlots", + "type": "uint256" + }, + { + "internalType": "uint16", + "name": "randomPercent", + "type": "uint16" + }, + { + "internalType": "uint256", + "name": "baseMultiplier", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "endTimestamp", + "type": "uint256" + } + ], + "internalType": "struct ICoin98GiftV2.InputConfig", + "name": "inputConfig", + "type": "tuple" + } + ], + "name": "__Coin98GiftV2Init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "broadcaster", + "outputs": [ + { + "internalType": "contract IBroadcaster", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_owner", + "type": "address" + } + ], + "name": "cancelGift", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + } + ], + "name": "claimReward", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "factory", + "outputs": [ + { + "internalType": "contract ICoin98GiftFactoryV2", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getGiftConfig", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "rewardToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "totalReward", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalSlots", + "type": "uint256" + }, + { + "internalType": "uint16", + "name": "randomPercent", + "type": "uint16" + }, + { + "internalType": "uint256", + "name": "baseMultiplier", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "meanRewardPerSlot", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "remainingReward", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "remainingSlots", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "endTimestamp", + "type": "uint256" + } + ], + "internalType": "struct ICoin98GiftV2.Config", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + } + ], + "name": "getInsertedSlot", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "slotNumber", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "reward", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "isInserted", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isClaimed", + "type": "bool" + } + ], + "internalType": "struct ICoin98GiftV2.Slot", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getRandomizer", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "nodeId", + "type": "bytes32" + } + ], + "name": "isUsedNodeId", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "projectKey", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "recipients", + "type": "address[]" + }, + { + "internalType": "bytes32[]", + "name": "nodeIds", + "type": "bytes32[]" + } + ], + "name": "submitRewardRecipients", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "withdraw", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_owner", + "type": "address" + } + ], + "name": "withdrawRemainingReward", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + } + ] export const ERC20ABI = [ { diff --git a/src/constants/contract.ts b/src/constants/contract.ts index 70715a5..c1e2b78 100644 --- a/src/constants/contract.ts +++ b/src/constants/contract.ts @@ -8,11 +8,11 @@ export enum CONTRACT_NAME { export const GIFT_CONTRACT = (contractName: CONTRACT_NAME, isDev: boolean = true): string => { const contracts : Record = { - "BROADCASTER_CONTRACT_ADDRESS" : isDev? '0x425b8B480cFf9911120e74b0F917d621aC80a002' : "0x5C8ABc6B9d669405BCB46aF982A4A9d53Ed9d2e7", - "RANDOMIZER_CONTRACT_ADDRESS" : isDev? '0xF7358FA54f269a2fD22b0b79bD5DaC275F159459' : "0x9822bF0915D1FDc29C5eaA68c93E115A8F3303Dd", - "COIN98_GIFT_CONTRACT_ADDRESS": isDev? '0x39841cA43709196B99fF0567172c532168c245ac' : "0xf25F71E761C09b18979aADAF1433104EE1945CBF", - "COIN98_GIFT_FACTORY_CONTRACT_ADDRESS": isDev? '0xFeb98A0a08Fbf51b4614Cc4b914CC05677A004fF' : "0xF827A1389d206194dEe7624F25015B86b376F26A", - "GAS_SPONSOR_CONTRACT_ADDRESS": isDev? '0x37F1cd0C822843595373aB9E0a5F09B6107b2dB6' : "0x095e458725ce80C54F2D595E4Ac4868B247DCC9e" + "BROADCASTER_CONTRACT_ADDRESS" : isDev? '0x8f15D886AC9BCE3b08066fCaaCB3d29A5D287B9e' : "0x5C8ABc6B9d669405BCB46aF982A4A9d53Ed9d2e7", + "RANDOMIZER_CONTRACT_ADDRESS" : isDev? '0x8EC1c86C16e6ED673737ef927a5a27E53eC29354' : "0x9822bF0915D1FDc29C5eaA68c93E115A8F3303Dd", + "COIN98_GIFT_CONTRACT_ADDRESS": isDev? '0x7631645693316BE37A9071fF75C11F0926741420' : "0xf25F71E761C09b18979aADAF1433104EE1945CBF", + "COIN98_GIFT_FACTORY_CONTRACT_ADDRESS": isDev? '0xB88996D92cf34bE25CA071bd81705abed141eCb8' : "0xF827A1389d206194dEe7624F25015B86b376F26A", + "GAS_SPONSOR_CONTRACT_ADDRESS": isDev? '0x464d8Af7211B30C1cBb7dAbA028F4C7B2eCC85Cc' : "0x095e458725ce80C54F2D595E4Ac4868B247DCC9e" } return contracts[contractName] } \ No newline at end of file diff --git a/src/packages/giftFactoy.ts b/src/packages/giftFactoy.ts index d6dfe2c..9e46249 100644 --- a/src/packages/giftFactoy.ts +++ b/src/packages/giftFactoy.ts @@ -149,12 +149,13 @@ export class GiftFactory extends GiftCore{ } async submitRewardRecipients(params: SubmitRewardParams): Promise{ - const { giftContractAddress, recipcients, privateKey } = params + const { giftContractAddress, recipcients, privateKey, nodeIds } = params try { const amdin = new EtherWallets(privateKey, this.provider) const giftContract = new ethers.Contract(giftContractAddress , GIFT_ABI['COIN98_GIFT_CONTRACT_ADDRESS'], amdin ) - const { hash } = await giftContract.connect(this.admin as ethers.Wallet).submitRewardRecipients(recipcients,{ + const nodeIdsBytes32 = nodeIds?.map((nodeId => ethers.utils.formatBytes32String(nodeId))) + const { hash } = await giftContract.connect(this.admin as ethers.Wallet).submitRewardRecipients(recipcients, nodeIdsBytes32,{ gasLimit: 650000 }) diff --git a/src/types/gifts.ts b/src/types/gifts.ts index 92e1686..b86182f 100644 --- a/src/types/gifts.ts +++ b/src/types/gifts.ts @@ -95,6 +95,7 @@ export interface RawData{ export interface SubmitRewardParams{ recipcients: string[], + nodeIds: string[], giftContractAddress: string, privateKey: string } \ No newline at end of file