마진 풀 SDK
마진 풀에 유동성을 공급하면 대여자는 자산에 대한 interest를 얻을 수 있고, margin trader에게는 차입 capacity를 제공한다. Margin Pool SDK는 유동성 포지션을 관리하고 리퍼럴 수수료를 얻기 위한 함수를 제공한다.
Margin Pool 함수
DeepBook Margin SDK는 마진 풀과 상호작용하기 위한 다음 함수를 제공한다.
mintSupplierCap
마진 풀에서 supply 및 출금에 사용할 수 있는 새 supplier capability를 생성하려면 mintSupplierCap을 사용한다. 하나의 SupplierCap은 여러 마진 풀에서 사용할 수 있다. 이 호출은 Transaction 객체를 받는 함수를 반환한다.
packages/deepbook-v3/src/transactions/marginPool.ts. You probably need to run `pnpm prebuild` and restart the site.supplyToMarginPool
자산을 마진 풀에 공급하고 interest를 얻으려면 supplyToMarginPool을 사용한다. fee를 referrer와 공유하기 위해 optional로 referral ID를 제공할 수 있다. 이 호출은 Transaction 객체를 받는 함수를 반환한다.
매개변수
coinKey: 자산 타입을 식별하는 String이다.supplierCap: supplier cap을 나타내는TransactionObjectArgument이다.amountToDeposit: supply할 amount를 나타내는 Number이다.referralId: referral ID를 나타내는 optional String이다.
packages/deepbook-v3/src/transactions/marginPool.ts. You probably need to run `pnpm prebuild` and restart the site.withdrawFromMarginPool
마진 풀에서 공급된 자산을 인출하려면 withdrawFromMarginPool을 사용한다. amount를 지정하지 않으면, 사용 가능한 모든 share를 인출한다. 이 호출은 Transaction 객체를 받는 함수를 반환한다.
매개변수
coinKey: 자산 타입을 식별하는 String이다.supplierCap: supplier cap을 나타내는TransactionObjectArgument이다.amountToWithdraw: 인출할 amount를 나타내는 optional Number이다.
packages/deepbook-v3/src/transactions/marginPool.ts. You probably need to run `pnpm prebuild` and restart the site.mintSupplyReferral
fee를 얻기 위한 supply referral을 생성하려면 mintSupplyReferral을 사용한다. 이 호출은 Transaction 객체를 받는 함수를 반환한다.
매개변수
coinKey: 자산 타입을 식별하는 String이다.
packages/deepbook-v3/src/transactions/marginPool.ts. You probably need to run `pnpm prebuild` and restart the site.withdrawReferralFees
누적된 리퍼럴 수수료를 인출하려면 withdrawReferralFees를 사용한다. 이 호출은 Transaction 객체를 받는 함수를 반환한다.
매개변수
coinKey: 자산 타입을 식별하는 String이다.referralId: referral ID를 나타내는 String이다.
packages/deepbook-v3/src/transactions/marginPool.ts. You probably need to run `pnpm prebuild` and restart the site.read-only 함수
다음 함수는 마진 풀 state를 수정하지 않고 쿼리한다.
풀 information
기본적인 풀 정보와 configuration을 쿼리한다.
packages/deepbook-v3/src/transactions/marginPool.ts. You probably need to run `pnpm prebuild` and restart the site.supply 및 차입 metric
현재 supply 및 차입 amount와 share를 쿼리한다.
packages/deepbook-v3/src/transactions/marginPool.ts. You probably need to run `pnpm prebuild` and restart the site.금리
이용률에 기반한 현재 금리를 쿼리한다.
packages/deepbook-v3/src/transactions/marginPool.ts. You probably need to run `pnpm prebuild` and restart the site.user 포지션
풀에서 supplier의 포지션을 쿼리한다.
packages/deepbook-v3/src/transactions/marginPool.ts. You probably need to run `pnpm prebuild` and restart the site.예시
다음 예시는 일반적인 마진 풀 operation을 시연한다.
supplier cap 생성
/**
* @description Mint a supplier cap for margin pool
* @returns A function that takes a Transaction object
*/
mintSupplierCap = () => (tx: Transaction) => {};
// Example usage
createSupplierCap = (tx: Transaction) => {
const supplierCap = tx.add(this.marginPoolContract.mintSupplierCap());
// Transfer to user or store for later use
tx.transferObjects([supplierCap], tx.pure.address(this.config.address));
};
유동성 supply
// Example: Supply 1000 USDC to the margin pool
supplyLiquidity = (tx: Transaction) => {
const coinKey = 'USDC';
const supplierCapId = '0x...'; // ID of your supplier cap
const supplierCap = tx.object(supplierCapId);
const amountToSupply = 1000;
tx.add(
this.marginPoolContract.supplyToMarginPool(
coinKey,
supplierCap,
amountToSupply,
// Optional: provide referral ID
),
);
};
referral로 supply
// Example: Supply 1000 USDC with a referral
supplyWithReferral = (tx: Transaction) => {
const coinKey = 'USDC';
const supplierCapId = '0x...';
const supplierCap = tx.object(supplierCapId);
const referralId = '0x...'; // Referral object ID
tx.add(
this.marginPoolContract.supplyToMarginPool(
coinKey,
supplierCap,
1000,
referralId, // Referral will earn fees
),
);
};
유동성 출금
// Example: Withdraw 500 USDC from the margin pool
withdrawLiquidity = (tx: Transaction) => {
const coinKey = 'USDC';
const supplierCapId = '0x...';
const supplierCap = tx.object(supplierCapId);
tx.add(this.marginPoolContract.withdrawFromMarginPool(coinKey, supplierCap, 500));
};
// Example: Withdraw all available liquidity
withdrawAll = (tx: Transaction) => {
const coinKey = 'USDC';
const supplierCapId = '0x...';
const supplierCap = tx.object(supplierCapId);
// No amount specified = withdraw all
tx.add(this.marginPoolContract.withdrawFromMarginPool(coinKey, supplierCap));
};
referral 생성 및 관리
// Example: Create a supply referral
createReferral = (tx: Transaction) => {
const coinKey = 'USDC';
tx.add(this.marginPoolContract.mintSupplyReferral(coinKey));
};
// Example: Withdraw referral fees
claimReferralFees = (tx: Transaction) => {
const coinKey = 'USDC';
const referralId = '0x...'; // Your referral object ID
tx.add(this.marginPoolContract.withdrawReferralFees(coinKey, referralId));
};
풀 state query
// Example: Check interest rate and utilization
checkPoolMetrics = async (tx: Transaction) => {
const coinKey = 'USDC';
// Get total supply and borrow
const totalSupply = tx.add(this.marginPoolContract.totalSupply(coinKey));
const totalBorrow = tx.add(this.marginPoolContract.totalBorrow(coinKey));
// Get current interest rate
const interestRate = tx.add(this.marginPoolContract.interestRate(coinKey));
// Query user position
const supplierCapId = '0x...';
const userShares = tx.add(this.marginPoolContract.userSupplyShares(coinKey, supplierCapId));
const userAmount = tx.add(this.marginPoolContract.userSupplyAmount(coinKey, supplierCapId));
};