Owldinal / OwlGame

0 stars 0 forks source link

Owldinal API Design #2

Open Owldinal opened 2 months ago

Owldinal commented 2 months ago

Owldinal 接口

需要质押的 token 分成两类:

  1. owldinal,指 owldinal nft,不直接提供收益,只提供 buff
  2. mysterybox / box,指 elf & magic fruit。这两种是同一个盲盒 nft,只是里面有个 boxType 的属性不同,所以只需要一个 tokenId就能从合约里面查询到这是 elf 还是 fruit。

大原则是所有写入的交互都是前端和合约之间产生的,所有的读交互都是前端和后端产生的。 后端通过监听合约事件的方式来更新数据库。

后端接口

GET 根据当前用户钱包地址获取信息的接口

image 2

GET /api/user/info?wallet=0xAABBCCDD

GET 根据当前用户钱包,获取 Owldinal 列表及 nft 列表

image 8

GET /api/user/owldinals?wallet=0xAABBCCDD&page=1&per_page=20 GET /api/user/boxes?wallet=0xAABBCCDD&page=1&per_page=20

{
    total,
    page,
    per_page,
    list: [
        {
            token id, type, token uri, earning, apr, status, operate
        }
    ]
}

GET 根据当前用户钱包,获取邀请列表

image

GET /api/user/inviter?wallet=0xAABBCCDD&page=1&per_page=20

{
    total,
    page,
    per_page,
    list: [
        {
            address
            // 之后需要确认这里还要啥属性,可能会需要每个被邀请人为邀请人所提供的收益
        }
    ]
}

GET 获取当前全局状态的接口

image 3

GET /api/game/info

另外关于这几个数据: total rewards usd / owl price / owl price change 前端直接调用 https://api.dexscreener.com/latest/dex/tokens/0x62e99191071Fc1C5947CF1e21Aa95708dcc51AdB 该api 获取 pairs[0].priceUsdpairs[0].priceChange.h24 进行展示

GET 获取total rewards 的变动历史(daily rewards)

image 4

GET /api/game/rewards_trend 一根线表示奖池的额度(totalPoolAmount):包括

  1. 初始注入的
  2. 因 mint 而进入奖池
  3. 因 fruit 的 4小时分配而减少 另一根线表示每日从 treasure 中释放的奖励 (allocatedRewards),包括: fruit 当天所分配出去的总奖励值
    {
        daily_view: {
            "from" "2024-04-01",
            "to":"2024-04-07",
            "dataPoints": [
                {
                  "date": "2023-04-01",
                  "totalPoolAmount": 50000,
                  "allocatedRewards": 1500
                },
                {
                  "date": "2023-04-02",
                  "totalPoolAmount": 52000,
                  "allocatedRewards": 1700
                },
                // more
            }
        }
        weeklyView: ....
        monthlyView: ....
    }

GET 获取 TreasuryRevenueHistory

image 7

这个数据仅包括通过 mint 进入奖池的资金数量 GET /api/game/rewards_history?cursor=18271&limit=20

{
    cursor: 18271,
    limit: 20,
    next_cursor: 18291,
        has_more: true,
    list: list <TreasuryRevenueHistory>,
}

struct TreasuryRevenueHistory {
    address
    operation           // 只有 minted
    description     // 只有 Gen1 Blind Box
    count 
    amount
    transaction hash
}

合约接口

Owldinal commented 2 months ago

Update: rewards_history 接口更新为游标翻页模式,避免翻页的时候有新数据进来导致重复数据。

GET /api/game/rewards_history?cursor=18271&limit=20

{
    cursor: 18271,
    limit: 20,
    next_cursor: 18291,
        has_more: true,
    list: list <TreasuryRevenueHistory>,
}
Owldinal commented 2 months ago

Update:

game info 接口中的 usd 价格数据需要前端自己调用第三方接口获取

GET /api/game/info

另外关于这几个数据: total rewards usd / owl price / owl price change 前端直接调用 https://api.dexscreener.com/latest/dex/tokens/0x62e99191071Fc1C5947CF1e21Aa95708dcc51AdB 该api 获取 pairs[0].priceUsdpairs[0].priceChange.h24 进行展示