Skip to content

Commit

Permalink
chore(script): add supply to loan markets
Browse files Browse the repository at this point in the history
  • Loading branch information
sander2 committed Feb 3, 2023
1 parent cdbc5d8 commit fec111b
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions scripts/init-testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ main().catch((err) => {
console.log(err);
});

type Currency = { Token: any } | { ForeignAsset: any } | { LendToken: any };
type LoansMarket = { collateralFactor?: any; liquidationThreshold?: any; reserveFactor?: any; closeFactor?: any; liquidateIncentive?: any; liquidateIncentiveReservedFactor?: any; rateModel?: any; state?: any; supplyCap?: any; borrowCap?: any; lendTokenId?: any };

function constructLendingSetup(api: ApiPromise) {
const addMarkets = [
api.tx.loans.addMarket(
const markets: [Currency, LoansMarket][] = [
[
{
Token: 'KBTC'
},
Expand All @@ -66,7 +69,7 @@ function constructLendingSetup(api: ApiPromise) {
borrowCap: "2000000000",
lendTokenId: { LendToken: 1 }
}
), api.tx.loans.addMarket(
], [
{
Token: 'KSM'
},
Expand All @@ -90,7 +93,7 @@ function constructLendingSetup(api: ApiPromise) {
borrowCap: "30000000000000000",
lendTokenId: { LendToken: 2 }
}
), api.tx.loans.addMarket(
], [
{
ForeignAsset: 1 // usdt
},
Expand All @@ -114,7 +117,7 @@ function constructLendingSetup(api: ApiPromise) {
borrowCap: "80000000000",
lendTokenId: { LendToken: 3 }
}
), api.tx.loans.addMarket(
], [
{
ForeignAsset: 2 // movr
},
Expand All @@ -138,30 +141,35 @@ function constructLendingSetup(api: ApiPromise) {
borrowCap: "20000000000000000000000",
lendTokenId: { LendToken: 4 }
}
)
],
];

const underlyingTokens = [
{ Token: "KBTC" },
{ Token: "KSM" },
{ ForeignAsset: 1 }, // USDT
{ ForeignAsset: 2 }, // MOVR
];
const addMarkets = markets.map(([token, market]) => {
return api.tx.loans.addMarket(token, market);
});

let addRewards = [
const addRewards = [
api.tx.utility.dispatchAs(
{ system: { Signed: treasuryAccount } },
api.tx.loans.addReward("100000000000000000000")
)
];
let activateMarketWithRewards = underlyingTokens.map((token) => {

const activateMarketWithRewards = markets.map(([token, _]) => {
return [
api.tx.loans.activateMarket(token),
api.tx.loans.updateMarketRewardSpeed(token, 10, 10),
]
}).reduce((x, y) => { return x.concat(y); });
}).flat();

const addSupply = markets.map(([token, market]) => {
return api.tx.utility.dispatchAs(
{ system: { Signed: treasuryAccount } },
api.tx.loans.mint(token, new BN(market.supplyCap).divn(10))
)
}).flat();

return addMarkets.concat(addRewards).concat(activateMarketWithRewards);
return [addMarkets, addRewards, activateMarketWithRewards, addSupply].flat()
}

function constructFundingSetup(api: ApiPromise) {
Expand Down Expand Up @@ -303,7 +311,7 @@ async function constructAmmSetup(api: ApiPromise) {
),
)
];
}).reduce((x, y) => { return x.concat(y); });
}).flat();

// note: this is before the batch is executed
const basePoolId = (await api.query.zenlinkStableAmm.nextPoolId() as any).toNumber();
Expand Down Expand Up @@ -510,7 +518,7 @@ async function setupParachain() {
constructVaultRegistrySetup(paraApi),
constructAnnuitySetup(paraApi),
await constructAmmSetup(paraApi),
].reduce((x, y) => { return x.concat(y); });
].flat();

const batched = paraApi.tx.utility.batchAll(calls);
const sudo = paraApi.tx.sudo.sudo(batched.method.toHex());
Expand Down

0 comments on commit fec111b

Please sign in to comment.