Skip to content

Commit

Permalink
chore: add funds limit
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Jan 2, 2025
1 parent 5527b3d commit d63f36e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Coin } from '@injectivelabs/ts-types'
import {
GoogleProtobufAny,
CosmwasmWasmV1Authz,
Expand All @@ -8,7 +9,8 @@ export declare namespace ContractExecutionAuthorization {
export interface Params {
contract: string
limit?: {
maxCalls: number
maxCalls?: number
amounts?: Coin[]
}
filter?: {
acceptedMessagesKeys: string[]
Expand Down Expand Up @@ -46,15 +48,38 @@ export default class ContractExecutionAuthorization extends BaseAuthorization<
grant.contract = params.contract

if (params.limit) {
const limit = CosmwasmWasmV1Authz.MaxCallsLimit.create()
if (params.limit.maxCalls && params.limit.amounts) {
const limit = CosmwasmWasmV1Authz.CombinedLimit.create()

limit.remaining = params.limit.maxCalls.toString()
limit.callsRemaining = params.limit.maxCalls.toString()
limit.amounts = params.limit.amounts

const any = GoogleProtobufAny.Any.create()
any.typeUrl = '/cosmwasm.wasm.v1.MaxCallsLimit'
any.value = CosmwasmWasmV1Authz.MaxCallsLimit.encode(limit).finish()
const any = GoogleProtobufAny.Any.create()
any.typeUrl = '/cosmwasm.wasm.v1.CombinedLimit'
any.value = CosmwasmWasmV1Authz.CombinedLimit.encode(limit).finish()

grant.limit = any
} else if (params.limit.maxCalls) {
const limit = CosmwasmWasmV1Authz.MaxCallsLimit.create()

limit.remaining = params.limit.maxCalls.toString()

const any = GoogleProtobufAny.Any.create()
any.typeUrl = '/cosmwasm.wasm.v1.MaxCallsLimit'
any.value = CosmwasmWasmV1Authz.MaxCallsLimit.encode(limit).finish()

grant.limit = any
grant.limit = any
} else if (params.limit.amounts) {
const limit = CosmwasmWasmV1Authz.MaxFundsLimit.create()

limit.amounts = params.limit.amounts

const any = GoogleProtobufAny.Any.create()
any.typeUrl = '/cosmwasm.wasm.v1.MaxFundsLimit'
any.value = CosmwasmWasmV1Authz.MaxFundsLimit.encode(limit).finish()

grant.limit = any
}
}

if (params.filter) {
Expand Down Expand Up @@ -99,9 +124,22 @@ export default class ContractExecutionAuthorization extends BaseAuthorization<
grant.contract = params.contract

if (params.limit) {
grant.limit = {
type: 'wasm/MaxCallsLimit',
remaining: params.limit.maxCalls.toString(),
if (params.limit.maxCalls && params.limit.amounts) {
grant.limit = {
type: 'wasm/CombinedLimit',
calls_remaining: params.limit.maxCalls.toString(),
amounts: params.limit.amounts,
}
} else if (params.limit.maxCalls) {
grant.limit = {
type: 'wasm/MaxCallsLimit',
remaining: params.limit.maxCalls.toString(),
}
} else if (params.limit.amounts) {
grant.limit = {
type: 'wasm/MaxFundsLimit',
amounts: params.limit.amounts,
}
}
}

Expand All @@ -126,9 +164,22 @@ export default class ContractExecutionAuthorization extends BaseAuthorization<
grant.contract = params.contract

if (params.limit) {
grant.limit = {
'@type': '/cosmwasm.wasm.v1.MaxCallsLimit',
remaining: params.limit.maxCalls.toString(),
if (params.limit.maxCalls && params.limit.amounts) {
grant.limit = {
'@type': '/cosmwasm.wasm.v1.CombinedLimit',
calls_remaining: params.limit.maxCalls.toString(),
amounts: params.limit.amounts,
}
} else if (params.limit.maxCalls) {
grant.limit = {
'@type': '/cosmwasm.wasm.v1.MaxCallsLimit',
remaining: params.limit.maxCalls.toString(),
}
} else if (params.limit.amounts) {
grant.limit = {
'@type': '/cosmwasm.wasm.v1.MaxFundsLimit',
amounts: params.limit.amounts,
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion proto/indexer/gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ BUILD_DIR=$ROOT_DIR/gen
PROTO_DIR=$ROOT_DIR/proto
TS_OUTPUT_DIR=$ROOT_DIR/proto-ts
TS_STUB_DIR=$ROOT_DIR/stub
injective_indexer_branch=v1.13.78-RC.1
injective_indexer_branch=dev

# remove old gen
rm -rf $BUILD_DIR
Expand Down

0 comments on commit d63f36e

Please sign in to comment.