Skip to content

Commit

Permalink
Merge pull request #37 from helix-bridge/xiaoch05-support-moonwell
Browse files Browse the repository at this point in the history
support moonwell on moonbeam
  • Loading branch information
xiaoch05 authored Aug 30, 2024
2 parents 14960bb + c6663c1 commit 5da1f76
Show file tree
Hide file tree
Showing 11 changed files with 3,469 additions and 26 deletions.
1,349 changes: 1,349 additions & 0 deletions src/abi/moonwellComptroller.ts

Large diffs are not rendered by default.

1,033 changes: 1,033 additions & 0 deletions src/abi/moonwellMToken.ts

Large diffs are not rendered by default.

188 changes: 188 additions & 0 deletions src/abi/moonwellOracle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
export const moonwellOracle = [
{
inputs: [{ internalType: "string", name: "_nativeToken", type: "string" }],
payable: false,
stateMutability: "nonpayable",
type: "constructor",
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "feed",
type: "address",
},
{
indexed: false,
internalType: "string",
name: "symbol",
type: "string",
},
],
name: "FeedSet",
type: "event",
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "oldAdmin",
type: "address",
},
{
indexed: false,
internalType: "address",
name: "newAdmin",
type: "address",
},
],
name: "NewAdmin",
type: "event",
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "asset",
type: "address",
},
{
indexed: false,
internalType: "uint256",
name: "previousPriceMantissa",
type: "uint256",
},
{
indexed: false,
internalType: "uint256",
name: "requestedPriceMantissa",
type: "uint256",
},
{
indexed: false,
internalType: "uint256",
name: "newPriceMantissa",
type: "uint256",
},
],
name: "PricePosted",
type: "event",
},
{
constant: true,
inputs: [],
name: "admin",
outputs: [{ internalType: "address", name: "", type: "address" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [{ internalType: "address", name: "asset", type: "address" }],
name: "assetPrices",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [{ internalType: "string", name: "symbol", type: "string" }],
name: "getFeed",
outputs: [
{
internalType: "contract AggregatorV2V3Interface",
name: "",
type: "address",
},
],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [
{ internalType: "contract MToken", name: "mToken", type: "address" },
],
name: "getUnderlyingPrice",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [],
name: "isPriceOracle",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [],
name: "nativeToken",
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: false,
inputs: [{ internalType: "address", name: "newAdmin", type: "address" }],
name: "setAdmin",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: false,
inputs: [
{ internalType: "address", name: "asset", type: "address" },
{ internalType: "uint256", name: "price", type: "uint256" },
],
name: "setDirectPrice",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: false,
inputs: [
{ internalType: "string", name: "symbol", type: "string" },
{ internalType: "address", name: "feed", type: "address" },
],
name: "setFeed",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: false,
inputs: [
{ internalType: "contract MToken", name: "mToken", type: "address" },
{
internalType: "uint256",
name: "underlyingPriceMantissa",
type: "uint256",
},
],
name: "setUnderlyingPrice",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
];
16 changes: 16 additions & 0 deletions src/base/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export interface SoftLimitAmount {
allowance: bigint;
}

export interface MulticallArgs {
address: string;
data: string;
}

export class EthereumContract {
protected contract: Contract;
public address: string;
Expand Down Expand Up @@ -858,4 +863,15 @@ export class MulticallContract extends EthereumContract {
}
return result;
}

async aggregate(args: MulticallArgs[]): Promise<string> {
const aggregateArgs = args.map((arg) => [arg.address, arg.data]);
let result = await this.staticCall(
"aggregate",
[aggregateArgs],
true,
null
);
return result;
}
}
3 changes: 2 additions & 1 deletion src/dataworker/dataworker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ export class DataworkerService implements OnModuleInit {
totalWithdrawAmount += BigInt(record.sendAmount);
transferIds.push(last(record.id.split("-")));
}
const withdrawAmountAvailable = Number(totalWithdrawAmount) / Number((new Any(1, decimals)).Number);
const withdrawAmountAvailable =
Number(totalWithdrawAmount) / Number(new Any(1, decimals).Number);

if (transferIds.length === 0) return null;

Expand Down
File renamed without changes.
33 changes: 12 additions & 21 deletions src/liquidity/lend/aave.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { Logger } from "@nestjs/common";
import { Wallet, HDNodeWallet, ethers } from "ethers";
import { AaveOracle, AaveL2Pool } from "./contract";
import { AaveOracle, AaveL2Pool } from "./aave.contract";
import {
MulticallContract,
zeroAddress,
WETHContract,
Erc20Contract,
} from "../../base/contract";
import { LendMarket, TxInfo, WithdrawBorrowBalance } from "./market";
import {
LendMarket,
TxInfo,
WithdrawBorrowBalance,
DebtStatus,
CollateralStatus,
maxU256,
} from "./market";
import {
LendTokenInfo,
CollateralInfo,
Expand Down Expand Up @@ -67,20 +74,6 @@ export interface AddressBook {
chains: ChainInfo[];
}

export enum DebtStatus {
HasDebt,
NoDebt,
}

export enum CollateralStatus {
CollateralFull,
CollateralLack,
}

export const maxU256: bigint = BigInt(
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);

export class AddressBookConfigure {
formalConfigure: AddressBook = {
version: "v3",
Expand Down Expand Up @@ -499,7 +492,9 @@ export class Aave extends LendMarket {
(dt) => dt.symbol == token.symbol
);
if (tokenInfo === undefined) {
throw new Error(`[Lend] DebtToken not exist symbol ${token.symbol}, chain ${chainName}`);
throw new Error(
`[Lend] DebtToken not exist symbol ${token.symbol}, chain ${chainName}`
);
}
//const collateralInfo = collaterals.find((c) => c.symbol === token.symbol);
return {
Expand Down Expand Up @@ -929,8 +924,4 @@ export class Aave extends LendMarket {
}
return txs;
}

address(): string {
return this.poolContract.address;
}
}
15 changes: 14 additions & 1 deletion src/liquidity/lend/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,27 @@ export interface WithdrawBorrowBalance {
borrow: bigint;
}

export enum DebtStatus {
HasDebt,
NoDebt,
}

export enum CollateralStatus {
CollateralFull,
CollateralLack,
}

export const maxU256: bigint = BigInt(
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);

export abstract class LendMarket {
public name: string;
public wrappedToken: string;
constructor(name: string, wtoken: string) {
this.name = name;
this.wrappedToken = wtoken;
}
abstract address(): string;
abstract lendingFromPoolTxs(
token: string,
amount: bigint,
Expand Down
Loading

0 comments on commit 5da1f76

Please sign in to comment.