Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/basic ve ocean #1595

Merged
merged 20 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ jobs:
path: ~/.npm
key: ${{ runner.os }}-test-unit-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-test-unit-${{ env.cache-name }}-

# Env var expansion workaround
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
- name: Set ADDRESS_FILE
run: echo "ADDRESS_FILE=${HOME}/.ocean/ocean-contracts/artifacts/address.json" >> $GITHUB_ENV
- name: Checkout Barge
uses: actions/checkout@v3
with:
Expand All @@ -57,6 +60,8 @@ jobs:
working-directory: ${{ github.workspace }}/barge
run: |
bash -x start_ocean.sh --no-aquarius --no-elasticsearch --no-provider --no-dashboard 2>&1 > start_ocean.log &
env:
CONTRACTS_VERSION: v1.1.3
- run: npm ci
- name: Wait for contracts deployment
working-directory: ${{ github.workspace }}/barge
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"web3": "^1.7.4"
},
"dependencies": {
"@oceanprotocol/contracts": "^1.0.0",
"@oceanprotocol/contracts": "^1.1.3",
"bignumber.js": "^9.0.2",
"cross-fetch": "^3.1.5",
"crypto-js": "^4.1.1",
Expand Down
3 changes: 3 additions & 0 deletions src/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ export * from './Router'
export * from './Datatoken'
export * from './NFT'
export * from './NFTFactory'
export * from './ve/VeOcean'
export * from './ve/VeFeeDistributor'
export * from './ve/VeAllocate'
117 changes: 117 additions & 0 deletions src/contracts/ve/VeAllocate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { AbiItem } from 'web3-utils'
import veAllocateABI from '@oceanprotocol/contracts/artifacts/contracts/ve/veAllocate.sol/veAllocate.json'
import { calculateEstimatedGas, sendTx } from '../../utils'
import { SmartContractWithAddress } from '../SmartContractWithAddress'
import { ReceiptOrEstimate } from '../../@types'
/**
* Provides an interface for veOcean contract
*/
export class VeAllocate extends SmartContractWithAddress {
getDefaultAbi(): AbiItem | AbiItem[] {
return veAllocateABI.abi as AbiItem[]
}

/**
* set a specific percentage of veOcean to a specific nft
* Maximum allocated percentage is 10000, so 1% is specified as 100
* @param {String} userAddress user address
* @param {String} amount Percentage used
* @param {String} nft NFT address to allocate to
* @param {String} chainId chainId of NFT
* @return {Promise<ReceiptOrEstimate>}
*/
public async setAllocation<G extends boolean = false>(
userAddress: string,
amount: string,
nft: string,
chainId: number,
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const estGas = await calculateEstimatedGas(
userAddress,
this.contract.methods.setAllocation,
amount,
nft,
chainId
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas

// Invoke function of the contract
const trxReceipt = await sendTx(
userAddress,
estGas + 1,
this.web3,
this.config?.gasFeeMultiplier,
this.contract.methods.setAllocation,
amount,
nft,
chainId
)
return <ReceiptOrEstimate<G>>trxReceipt
}

/**
* set specific percetage of veOcean to multiple nfts
* Maximum allocated percentage is 10000, so 1% is specified as 100
* @param {String} userAddress user address
* @param {String[]} amount Array of percentages used
* @param {String[]} nft Array of NFT addresses
* @param {String[]} chainId Array of chainIds
* @return {Promise<ReceiptOrEstimate>}
*/
public async setBatchAllocation<G extends boolean = false>(
userAddress: string,
amount: string[],
nft: string[],
chainId: number[],
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const estGas = await calculateEstimatedGas(
userAddress,
this.contract.methods.setBatchAllocation,
amount,
nft,
chainId
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas

// Invoke function of the contract
const trxReceipt = await sendTx(
userAddress,
estGas + 1,
this.web3,
this.config?.gasFeeMultiplier,
this.contract.methods.setBatchAllocation,
amount,
nft,
chainId
)
return <ReceiptOrEstimate<G>>trxReceipt
}

/** Get totalAllocation for address
* @param {String} userAddress user address
* @return {Promise<number>}
*/
public async getTotalAllocation(userAddress: string): Promise<number> {
const allocation = await this.contract.methods.getTotalAllocation(userAddress).call()
return allocation
}

/** Get getveAllocation for address, nft, chainId
* @param {String} userAddress user address
* @param {String} nft NFT address to allocate to
* @param {String} chainId chainId of NFT
* @return {Promise<number>}
*/
public async getVeAllocation(
userAddress: string,
nft: string,
chainId: string
): Promise<number> {
const allocation = await this.contract.methods
.getveAllocation(userAddress, nft, chainId)
.call()
return allocation
}
}
74 changes: 74 additions & 0 deletions src/contracts/ve/VeFeeDistributor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { AbiItem } from 'web3-utils'
import veFeeABI from '@oceanprotocol/contracts/artifacts/contracts/ve/veFeeDistributor.vy/veFeeDistributor.json'
import { calculateEstimatedGas, sendTx } from '../../utils'
import { SmartContractWithAddress } from '../SmartContractWithAddress'
import { ReceiptOrEstimate } from '../../@types'
/**
* Provides an interface for veOcean contract
*/
export class VeFeeDistributor extends SmartContractWithAddress {
getDefaultAbi(): AbiItem | AbiItem[] {
return veFeeABI.abi as AbiItem[]
}

/**
* Claim fees for `userAddress`
* Each call to claim look at a maximum of 50 user veOCEAN points.
For accounts with many veOCEAN related actions, this function
may need to be called more than once to claim all available
fees. In the `Claimed` event that fires, if `claim_epoch` is
less than `max_epoch`, the account may claim again
* @param {String} userAddress user address
* @return {Promise<ReceiptOrEstimate>}
*/
public async claim<G extends boolean = false>(
userAddress: string,
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const estGas = await calculateEstimatedGas(userAddress, this.contract.methods.claim)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas

// Invoke function of the contract
const trxReceipt = await sendTx(
userAddress,
estGas + 20000,
this.web3,
this.config?.gasFeeMultiplier,
this.contract.methods.claim
)
return <ReceiptOrEstimate<G>>trxReceipt
}

/**
* Make multiple fee claims in a single call
Used to claim for many accounts at once, or to make
multiple claims for the same address when that address
has significant veOCEAN history
* @param {String} fromUserAddress user address that sends the tx
* @param {String} addresses array of addresses to claim
* @return {Promise<ReceiptOrEstimate>}
*/
public async claimMany<G extends boolean = false>(
fromUserAddress: string,
addresses: string[],
estimateGas?: G
): Promise<ReceiptOrEstimate<G>> {
const estGas = await calculateEstimatedGas(
fromUserAddress,
this.contract.methods.claim_many,
addresses
)
if (estimateGas) return <ReceiptOrEstimate<G>>estGas

// Invoke function of the contract
const trxReceipt = await sendTx(
fromUserAddress,
estGas + 20000,
this.web3,
this.config?.gasFeeMultiplier,
this.contract.methods.claim_many,
addresses
)
return <ReceiptOrEstimate<G>>trxReceipt
}
}