마진 풀 SDK
margin pool에 liquidity를 공급하면 lender는 asset에 대한 interest를 얻을 수 있고, margin trader에게는 차입 capacity를 제공한다. Margin Pool SDK는 liquidity position을 관리하고 referral fee를 얻기 위한 함수를 제공한다.
Margin Pool functions
DeepBook Margin SDK는 margin pool과 상호작용하기 위한 다음 함수를 제공한다.
mintSupplierCap
margin pool에서 supply 및 withdraw에 사용할 수 있는 새 supplier capability를 생성하려면 mintSupplierCap을 사용한다. 하나의 SupplierCap은 여러 margin pool에서 사용할 수 있다. 이 호출은 Transaction object를 받는 함수를 반환한다.
packages/deepbook-v3/src/transactions/marginPool.ts. You probably need to run `pnpm prebuild` and restart the site.supplyToMarginPool
asset을 margin pool에 공급하고 interest를 얻으려면 supplyToMarginPool을 사용한다. fee를 referrer와 공유하기 위해 optional로 referral ID를 제공할 수 있다. 이 호출은 Transaction object를 받는 함수를 반환한다.
Parameters
coinKey: asset 타입을 식별하는 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
margin pool에서 공급된 asset을 인출하려면 withdrawFromMarginPool을 사용한다. amount를 지정하지 않으면, 사용 가능한 모든 share를 인출한다. 이 호출은 Transaction object를 받는 함수를 반환한다.
Parameters
coinKey: asset 타입을 식별하는 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 object를 받는 함수를 반환한다.
Parameters
coinKey: asset 타입을 식별하는 String이다.
packages/deepbook-v3/src/transactions/marginPool.ts. You probably need to run `pnpm prebuild` and restart the site.withdrawReferralFees
누적된 referral fee를 인출하려면 withdrawReferralFees를 사용한다. 이 호출은 Transaction object를 받는 함수를 반환한다.
Parameters
coinKey: asset 타입을 식별하는 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 functions
다음 함수는 margin pool state를 수정하지 않고 쿼리한다.
Pool information
기본적인 pool 정보와 configuration을 쿼리한다.
packages/deepbook-v3/src/transactions/marginPool.ts. You probably need to run `pnpm prebuild` and restart the site.Supply and borrow metrics
현재 supply 및 borrow amount와 share를 쿼리한다.
packages/deepbook-v3/src/transactions/marginPool.ts. You probably need to run `pnpm prebuild` and restart the site.Interest rate
utilization에 기반한 현재 interest rate를 쿼리한다.
packages/deepbook-v3/src/transactions/marginPool.ts. You probably need to run `pnpm prebuild` and restart the site.User positions
pool에서 supplier의 position을 쿼리한다.
packages/deepbook-v3/src/transactions/marginPool.ts. You probably need to run `pnpm prebuild` and restart the site.Examples
다음 예시는 일반적인 margin pool operation을 시연한다.
Create a supplier cap
/**
* @description margin pool용 supplier cap을 mint한다
* @returns Transaction object를 받는 함수를 반환한다
*/
mintSupplierCap = () => (tx: Transaction) => {};
// 예시 사용
createSupplierCap = (tx: Transaction) => {
const supplierCap = tx.add(this.marginPoolContract.mintSupplierCap());
// user에게 전송하거나 나중에 사용할 수 있도록 저장한다
tx.transferObjects([supplierCap], tx.pure.address(this.config.address));
};
Supply liquidity
// 예시: margin pool에 USDC 1000을 예치한다
supplyLiquidity = (tx: Transaction) => {
const coinKey = 'USDC';
const supplierCapId = '0x...'; // supplier cap의 ID
const supplierCap = tx.object(supplierCapId);
const amountToSupply = 1000;
tx.add(
this.marginPoolContract.supplyToMarginPool(
coinKey,
supplierCap,
amountToSupply,
// 선택 사항: referral ID를 제공한다
),
);
};
Supply with referral
// 예시: referral과 함께 USDC 1000을 예치한다
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이 fee를 적립한다
),
);
};
Withdraw liquidity
// 예시: margin pool에서 USDC 500을 출금한다
withdrawLiquidity = (tx: Transaction) => {
const coinKey = 'USDC';
const supplierCapId = '0x...';
const supplierCap = tx.object(supplierCapId);
tx.add(this.marginPoolContract.withdrawFromMarginPool(coinKey, supplierCap, 500));
};
// 예시: 사용 가능한 모든 유동성을 출금한다
withdrawAll = (tx: Transaction) => {
const coinKey = 'USDC';
const supplierCapId = '0x...';
const supplierCap = tx.object(supplierCapId);
// amount를 지정하지 않으면 전부 출금한다
tx.add(this.marginPoolContract.withdrawFromMarginPool(coinKey, supplierCap));
};
Create and manage referrals
// 예시: supply referral을 생성한다
createReferral = (tx: Transaction) => {
const coinKey = 'USDC';
tx.add(this.marginPoolContract.mintSupplyReferral(coinKey));
};
// 예시: referral fee를 출금한다
claimReferralFees = (tx: Transaction) => {
const coinKey = 'USDC';
const referralId = '0x...'; // referral object의 ID
tx.add(this.marginPoolContract.withdrawReferralFees(coinKey, referralId));
};
Query pool state
// 예시: 금리와 이용률을 확인한다
checkPoolMetrics = async (tx: Transaction) => {
const coinKey = 'USDC';
// 총 예치량과 차입량을 가져온다
const totalSupply = tx.add(this.marginPoolContract.totalSupply(coinKey));
const totalBorrow = tx.add(this.marginPoolContract.totalBorrow(coinKey));
// 현재 금리를 가져온다
const interestRate = tx.add(this.marginPoolContract.interestRate(coinKey));
// user position을 조회한다
const supplierCapId = '0x...';
const userShares = tx.add(this.marginPoolContract.userSupplyShares(coinKey, supplierCapId));
const userAmount = tx.add(this.marginPoolContract.userSupplyAmount(coinKey, supplierCapId));
};