h-newfi

1.4.6 • Public • Published
npm publish

import { NewFiV3 } from "h-newfi"

async function init() {
    let accounts = await ethereum.enable()
    return {
        provider: ethereum,
        account: accounts[0]
    }
}


//部署Staked合约
async function deploy_v3() {
    let newfi = await initObj_v3()
    let route = "0x9a489505a00cE272eAa5e07Dba6491314CaE3796"
    let quotev2 = "0xbC203d7f83677c7ed3F7acEc959963E7F4ECC5C2"
    let compute = "0x8F61a05142ca5aDb54706d208C0AC370c8Fd7Cb0"
    let signer = "0x55959f0D5e1b7DC57fe4079e596b8BBafFF123B1"
    let { _address } = await newfi.deploy({
        route,quotev2,compute,signer
    })
    console.log(_address)
}





async function initObj_v3() {
    let { provider,account } = await this.init()
    let newfi = new NewFiV3({
        provider,account,
        contract: "0xdB8C6A407e6d088CF27788ef99e47a2e5cC13cb8"
    })
    return newfi
}
//参与质押
async function Invest_v3() {
    let newfi = await initObj_v3()
    <!-- 项目ID -->
    let id = 1
    <!-- 质押金额 -->
    let amount = 4
    let result = await newfi.Invest({
        id,amount
    })
    console.log(result)
    <!-- 查询合约中某个币种的余额 -->
    let balance = await newfi.balanceOf("币种合约地址")
}
// 构建项目
async function poolCreat_v3() {
    let newfi = await initObj_v3()
    let id = 5     //项目ID
    let token0 = "0xaB1a4d4f1D656d2450692D237fdD6C7f9146e814"//质押币种合约地址
    let token1 = "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd"//组成Farm的另外一种币合约址
    let fee = "500"   //流动性手续费
    let point = "500000"
    let result = await newfi.poolCreat({
        id,token0,token1,fee,point
    })
    console.log(result)
}
//计算对象 用于部署Compute合约
Compute














<!-- 示例 -->

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./static/style.css">
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            padding: 24px;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            justify-content: space-between;
        }

        .btnItem {
            padding: 8px 20px;
            border-radius: 4px;
            background-color: cornflowerblue;
            color: #fff;
            font-size: 14px;
            font-weight: bold;
            cursor: pointer;
            margin-bottom: 24px;
        }
    </style>
</head>

<body>
    <!-- <span class="btnItem" onclick="deploy()">deploy</span>
    <span class="btnItem" onclick="poolCreat()">poolCreat</span>
    <span class="btnItem" onclick="view()">view</span>
    <span class="btnItem" onclick="Invest()">Invest</span>
    <span class="btnItem" onclick="tokenExtract()">tokenExtract</span>
    <span class="btnItem" onclick="Convert()">Convert</span>
    <span class="btnItem" onclick="Extract()">Extract</span>
    <span class="btnItem" onclick="deployLiquidity()">deployLiquidity</span> -->



    <span class="btnItem" onclick="deploy_v3()">deploy_v3</span>
    <span class="btnItem" onclick="Invest_v3()">Invest_v3</span>
    <span class="btnItem" onclick="poolCreat_v3()">poolCreat_v3</span>
    <span class="btnItem" onclick="Challenge_v3()">Challenge_v3</span>
    <span class="btnItem" onclick="pendingReward_v3()">pendingReward_v3</span>
    <span class="btnItem" onclick="balanceOf_v3()">balanceOf_v3</span>
    <span class="btnItem" onclick="harvestFarm_v3()">harvestFarm_v3</span>
    
    <span class="btnItem" onclick="withdrawFarm_v3()">withdrawFarm_v3</span>
    <span class="btnItem" onclick="withdrawNFT_v3()">withdrawNFT_v3</span>
    <span class="btnItem" onclick="poolControl_v3()">poolControl_v3</span>
    <span class="btnItem" onclick="Extract_v3()">Extract_v3</span>
    <span class="btnItem" onclick="withdrawFarmPosition_v3()">withdrawFarmPosition_v3</span>
    <span class="btnItem" onclick="poolTokenID_v3()">poolTokenID_v3</span>
    <script src="./bundle.js"></script>
    <script>
        // USDT   0xf2DC315D6591599701d4346c7A8E911C24d79740
        // CAKE   0xFa60D973F7642B748046464e165A65B7323b0DEE
        // BUSDT  0x8516Fc284AEEaa0374E66037BD2309349FF728eA
        // JC     0xD703E8617179f5D86CCf95a57694f9bA8335A5E1
        // WBNB   0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd
        // TF     0x3E465b0B46D552Bbf8396345b768d31e5cf9c5BE
        // 1000000000000000000000
        async function deployLiquidity() {
            let { provider,account } = await this.init()
            let newfi = new Liquidity({
                provider,account
            })
            let { _address } = await newfi.deploy()
            console.log(_address)
        }
        async function initObj_v3() {
            let { provider,account } = await this.init()
            let newfi = new NewFiV3({
                provider,account,
                contract: "0x07D9c67602241E4c0a5c02042788f79d997ab85f"
            })
            return newfi
        }
        async function Invest_v3() {
            let newfi = await initObj_v3()
            let id = 5
            let amount = 0.0003
            let result = await newfi.Invest({
                id,amount
            })
            console.log(result)
        }

        async function Extract_v3() {
            let newfi = await initObj_v3()

            let result = await newfi.Extract({
                id:5,
                token:"0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd",
                // token:"0x8d008b313c1d6c7fe2982f62d32da7507cf43551",
                amount:0.00001
            })
            console.log(result)
        }
        
        async function poolControl_v3() {
            let newfi = await initObj_v3()
            let id = 5
            let inStatus = true
            let outStatus = true
            let result = await newfi.poolControl({
                id,inStatus,outStatus
            })
            console.log(result)
        }

        async function withdrawNFT_v3() {
            let newfi = await initObj_v3()
            let tokenID = 619
            let result = await newfi.withdrawNFT(tokenID)
            console.log(result)
        }

        async function withdrawFarm_v3() {
            let newfi = await initObj_v3()
            let id = 5
            let result = await newfi.withdrawFarm(id)
            console.log(result)
        }

        async function poolTokenID_v3() {
            let newfi = await initObj_v3()
            let id = 5
            let tokenId = "623"
    
            let result = await newfi.poolTokenID({
                id,tokenId
            })
            console.log(result)
        }

        async function withdrawFarmPosition_v3() {
            let newfi = await initObj_v3()
            let id = 5
            let result = await newfi.withdrawFarmPosition(id)
            console.log(result)
        }

        async function harvestFarm_v3() {
            let newfi = await initObj_v3()
            let id = 5
            let result = await newfi.harvestFarm(id)
            console.log(result)
        }

        async function Challenge_v3() {
            let newfi = await initObj_v3()
            let id = 5
            let result = await newfi.Challenge(id)
            console.log(result)
        }

        async function pendingReward_v3() {
            let newfi = await initObj_v3()
            let id = 5
            let result = await newfi.pendingReward(id)
            console.log(result)
        }
        async function balanceOf_v3() {
            let newfi = await initObj_v3()
            // weth => eth
            let token = "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd"
            let result = await newfi.balanceOf(token)
            console.log(result)
        }

        async function poolCreat_v3() {
            let newfi = await initObj_v3()
            let id = 5     //项目ID
            let token0 = "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd"//质押币种合约地址
            let token1 = "0x8d008B313C1d6C7fE2982F62d32Da7507cF43551"//组成Farm的另外一种币种合约地址
            let fee = 2500   //流动性手续费
            let point = 500000  //滑点
            let result = await newfi.poolCreat({
                id,token0,token1,fee,point
            })
            console.log(result)
        }

        async function deploy_v3() {
            let newfi = await initObj_v3()
            let route = "0x9a489505a00cE272eAa5e07Dba6491314CaE3796"
            let quotev2 = "0xbC203d7f83677c7ed3F7acEc959963E7F4ECC5C2"
            let compute = "0x8F61a05142ca5aDb54706d208C0AC370c8Fd7Cb0"
            let signer = "0x55959f0D5e1b7DC57fe4079e596b8BBafFF123B1"

            let { _address } = await newfi.deploy({
                route,quotev2,compute,signer
            })
            console.log(_address)
        }
        async function deploy() {
            let newfi = await initObj()
            let route = "0xd99d1c33f9fc3444f8101754abc46c52416550d1"
            let farm = "0xb4a466911556e39210a6bb2faecbb59e4eb7e43d"
            let signer = "0x55959f0D5e1b7DC57fe4079e596b8BBafFF123B1"

            let { _address } = await newfi.deploy({
                route,farm,signer
            })
            console.log(_address)
        }
        async function view() {
            let newfi = await initObj()
            let route = await newfi.route()
            console.log(route)
            let factory = await newfi.factory()
            console.log(factory)
            let farm = await newfi.farm()
            console.log(farm)
            let weth = await newfi.weth()
            console.log(weth)
        }

        async function tokenExtract() {
            let newfi = await initObj()

            let result = await newfi.tokenExtract({
                token:"0xFa60D973F7642B748046464e165A65B7323b0DEE",
                amount:"220000"
            })
            console.log(result)
        }
        async function poolCreat() {
            let newfi = await initObj()

            let result = await newfi.poolCreat({
                id:1,
                token0:"0xFa60D973F7642B748046464e165A65B7323b0DEE",
                token1:"0x0000000000000000000000000000000000000000",
                pid:4,
                point:50
            })
            console.log(result)
        }
        async function Invest() {
            let newfi = await initObj()
            let id = 2
            let amount = 0.000005

            let pool = await newfi.pool(id)
            let token = pool.token0.token
            let kind = pool.token0.kind

            let balance = 0
            let inToken;
            if(kind == 3) {
                inToken = new HERC20({ ...newfi.network, contract: token })
            }else {
                inToken = new HERC20({ ...newfi.network, contract: "" })
            }
            balance = await inToken.balanceOf(newfi.web3.eth.defaultAccount)
            console.log(balance)
            balance = await inToken.fromAmount(balance);
            
            if(parseFloat(balance) >= parseFloat(balance)) {
                let result = await newfi.Invest({
                    id,amount
                })
            }else {
                cosnole.log("余额不足")
            }

            // let result = await newfi.Invest({
            //     id,amount
            // })

            
            // console.log(result)
        }
        async function Extract() {
            let newfi = await initObj()

            let result = await newfi.Extract({
                id:1,
                token:"0xFa60D973F7642B748046464e165A65B7323b0DEE",
                amount:4000
            })
            console.log(result)
        }
        async function Convert() {
            let newfi = await initObj()

            let result = await newfi.Convert({
                tokenIn:"0xfa60d973f7642b748046464e165a65b7323b0dee",
                tokenOut:"0x0000000000000000000000000000000000000000",
                inAmount:3000000,
                outAmount:0
            })
            console.log(result)
        }
        async function init() {
            let accounts = await ethereum.enable()
            return {
                provider: ethereum,
                account: accounts[0]
            }
        }
        async function initObj() {
            let { provider,account } = await this.init()
            let newfi = new NewFi({
                provider,account,
                contract: "0x633c995f37cc1bDdcb2CB3068e74A99727fcF408"
            })
            return newfi
        }

        

       

    </script>
</body>

</html>

Readme

Keywords

none

Package Sidebar

Install

npm i h-newfi

Weekly Downloads

51

Version

1.4.6

License

ISC

Unpacked Size

810 kB

Total Files

21

Last publish

Collaborators

  • wangbolvshu
  • huang_cj