Skip to content

Commit

Permalink
feat: external calls for Balancer (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
iherger authored Oct 4, 2023
1 parent 5b1ba3e commit 6269525
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-terms-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@enzymefinance/sdk": patch
---

Add external calls for Balancer
49 changes: 40 additions & 9 deletions packages/sdk/src/internal/External/BalancerV2.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
import { Viem } from "@enzymefinance/sdk/Utils";
import { type Address, type PublicClient } from "viem";

const mintAbi = {
inputs: [{ internalType: "address", name: "gauge", type: "address" }],
name: "mint",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "nonpayable",
type: "function",
} as const;
const minterAbi = [
{
inputs: [{ internalType: "address", name: "gauge", type: "address" }],
name: "mint",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "nonpayable",
type: "function",
},
] as const;

const gaugeAbi = [
{
inputs: [
{ internalType: "address", name: "user", type: "address" },
{ internalType: "address", name: "rewardToken", type: "address" },
],
name: "claimable_reward",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
] as const;

export async function getMinterRewards(
client: PublicClient,
args: Viem.ContractCallParameters<{
minter: Address;
beneficiary: Address;
gauge: Address;
minter: Address;
}>,
) {
const { result } = await Viem.simulateContract(client, args, {
abi: [mintAbi],
abi: minterAbi,
functionName: "mint",
address: args.minter,
args: [args.gauge],
Expand All @@ -27,3 +42,19 @@ export async function getMinterRewards(

return result;
}

export async function getClaimableRewards(
client: PublicClient,
args: Viem.ContractCallParameters<{
gauge: Address;
user: Address;
rewardToken: Address;
}>,
) {
return Viem.readContract(client, args, {
abi: gaugeAbi,
functionName: "claimable_reward",
address: args.gauge,
args: [args.user, args.rewardToken],
});
}

0 comments on commit 6269525

Please sign in to comment.