From 2f12b6ad49ac0a59f9b55b80809c83f2f6d7f8f0 Mon Sep 17 00:00:00 2001 From: Gregory Hill Date: Fri, 9 Feb 2024 13:48:59 +0000 Subject: [PATCH 1/4] add script to register asset Signed-off-by: Gregory Hill --- package.json | 2 +- scripts/register-asset.ts | 133 ++++++++++++++++++++++++++++++++++++++ tsconfig.json | 5 +- 3 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 scripts/register-asset.ts diff --git a/package.json b/package.json index 8f82e15bd..3064d693d 100644 --- a/package.json +++ b/package.json @@ -130,4 +130,4 @@ ], "testTimeout": 30000 } -} +} \ No newline at end of file diff --git a/scripts/register-asset.ts b/scripts/register-asset.ts new file mode 100644 index 000000000..3e7ecec1a --- /dev/null +++ b/scripts/register-asset.ts @@ -0,0 +1,133 @@ +/* eslint @typescript-eslint/no-var-requires: "off" */ +import { createSubstrateAPI } from "../src/factory"; +import { ApiPromise } from "@polkadot/api"; +import { cryptoWaitReady } from "@polkadot/util-crypto"; +import { printDiscordProposal } from "./util"; + +main().catch((err) => { + console.log("Error thrown by script:"); + console.log(err); +}); + +const NEW_ASSET = { + metadata: { + decimals: 6, + name: "USD Coin", + symbol: "USDC", + existentialDeposit: 0, + location: { + V3: { + parents: 1, + interior: { + X3: [ + { + Parachain: 1000 + }, + { + PalletInstance: 50 + }, + { + GeneralIndex: 1337 + } + ] + } + } + }, + additional: { feePerSecond: 11888560, coingeckoId: "usd-coin" } + }, + pools: [ + { + token1: { Token: "INTR" }, + dexFees: 15, + }, + ], + market: { + collateralFactor: 630000, + liquidationThreshold: 670000, + reserveFactor: 200000, + closeFactor: 500000, + liquidateIncentive: "1100000000000000000", + liquidateIncentiveReservedFactor: 25000, + rateModel: { + Jump: { + baseRate: 0, + jumpRate: "50000000000000000", + fullRate: "500000000000000000", + jumpUtilization: 900000 + } + }, + state: "Pending", + supplyCap: "10000000000", + borrowCap: "10000000000", + lendTokenId: { LendToken: 5 }, // NOTE: make sure this is free + supplyIncentivesPerBlock: 0 + }, + vaultParams: { + wrappedCurrency: { Token: "IBTC" }, + liquidationCollateral: "1450000000000000000", + premiumRedeem: "1650000000000000000", + secureCollateral: "1800000000000000000", + minimumCollateral: "20000000000000", + systemCollateralCeiling: "38000000000000000", + } +}; + +function vaultRegistryCalls( + api: ApiPromise, + collateralCurrency: { ForeignAsset: number }, +) { + const { + wrappedCurrency, + liquidationCollateral, + premiumRedeem, + secureCollateral, + minimumCollateral, + systemCollateralCeiling + } = NEW_ASSET.vaultParams; + const currencyPair = { + collateral: collateralCurrency, + wrapped: wrappedCurrency, + }; + return [ + api.tx.vaultRegistry.setLiquidationCollateralThreshold(currencyPair, liquidationCollateral), + api.tx.vaultRegistry.setPremiumRedeemThreshold(currencyPair, premiumRedeem), + api.tx.vaultRegistry.setSecureCollateralThreshold(currencyPair, secureCollateral), + api.tx.vaultRegistry.setMinimumCollateral(currencyPair.collateral, minimumCollateral), + api.tx.vaultRegistry.setSystemCollateralCeiling(currencyPair, systemCollateralCeiling), + ]; +} + +async function main(): Promise { + await cryptoWaitReady(); + + const parachainEndpoint = "wss://api.interlay.io/parachain"; + const paraApi = await createSubstrateAPI(parachainEndpoint); + + const lastAssetId = await paraApi.query.assetRegistry.lastAssetId(); + const nextAssetId = lastAssetId.toNumber() + 1; + const currencyId = { ForeignAsset: nextAssetId }; + + const allCalls = [ + paraApi.tx.assetRegistry.registerAsset(NEW_ASSET.metadata, nextAssetId) + ]; + + allCalls.push(...NEW_ASSET.pools.map(pool => + paraApi.tx.dexGeneral.createPair(currencyId, pool.token1, pool.dexFees) + )) + + allCalls.push( + ...[ + paraApi.tx.loans.addMarket(currencyId, NEW_ASSET.market), + paraApi.tx.loans.activateMarket(currencyId) + ] + ); + + allCalls.push(...vaultRegistryCalls(paraApi, currencyId)); + + const batched = paraApi.tx.utility.batchAll(allCalls); + + const title = `Register ${NEW_ASSET.metadata.symbol}`; + printDiscordProposal(title, batched, parachainEndpoint, paraApi); + + await paraApi.disconnect(); +} diff --git a/tsconfig.json b/tsconfig.json index a9c4daef7..bbb16a4a1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,6 @@ "extends": "./tsconfig-base.json", "compilerOptions": { "target": "ES6", - "module": "ES6", - "outDir": "build/esm", + "module": "CommonJS", } -} +} \ No newline at end of file From 08112c49898ef68f525a1bbf1752633b38d6bfe1 Mon Sep 17 00:00:00 2001 From: Gregory Hill Date: Fri, 9 Feb 2024 16:14:14 +0000 Subject: [PATCH 2/4] update usdc parameters Signed-off-by: Gregory Hill --- scripts/register-asset.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/scripts/register-asset.ts b/scripts/register-asset.ts index 3e7ecec1a..e92ccc263 100644 --- a/scripts/register-asset.ts +++ b/scripts/register-asset.ts @@ -38,37 +38,37 @@ const NEW_ASSET = { pools: [ { token1: { Token: "INTR" }, - dexFees: 15, + dexFees: 100, }, ], market: { - collateralFactor: 630000, - liquidationThreshold: 670000, - reserveFactor: 200000, - closeFactor: 500000, - liquidateIncentive: "1100000000000000000", + collateralFactor: 650000, // 65% + liquidationThreshold: 870000, // 87% + reserveFactor: 100000, // 10% + closeFactor: 500000, // 50% + liquidateIncentive: "1100000000000000000", // 110% liquidateIncentiveReservedFactor: 25000, rateModel: { Jump: { baseRate: 0, - jumpRate: "50000000000000000", - fullRate: "500000000000000000", - jumpUtilization: 900000 + jumpRate: "100000000000000000", // 10% + fullRate: "500000000000000000", // 50% + jumpUtilization: 800000 // 80% } }, state: "Pending", - supplyCap: "10000000000", - borrowCap: "10000000000", + supplyCap: "2000000000000", // 2,000,000 + borrowCap: "2000000000000", // 2,000,000 lendTokenId: { LendToken: 5 }, // NOTE: make sure this is free supplyIncentivesPerBlock: 0 }, vaultParams: { wrappedCurrency: { Token: "IBTC" }, - liquidationCollateral: "1450000000000000000", - premiumRedeem: "1650000000000000000", - secureCollateral: "1800000000000000000", - minimumCollateral: "20000000000000", - systemCollateralCeiling: "38000000000000000", + liquidationCollateral: "1050000000000000000", // 105% + premiumRedeem: "1150000000000000000", // 115% + secureCollateral: "1550000000000000000", // 155% + minimumCollateral: "1550000000", // 1550 USDC + systemCollateralCeiling: "2000000000000", // 2,000,000 USDC } }; From 4af205ffa68c30fa04c1a0a055003e331479b8e8 Mon Sep 17 00:00:00 2001 From: Gregory Hill Date: Mon, 12 Feb 2024 13:18:35 +0000 Subject: [PATCH 3/4] add vault params for lending asset Signed-off-by: Gregory Hill --- scripts/register-asset.ts | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/scripts/register-asset.ts b/scripts/register-asset.ts index e92ccc263..562f2eaac 100644 --- a/scripts/register-asset.ts +++ b/scripts/register-asset.ts @@ -10,6 +10,7 @@ main().catch((err) => { }); const NEW_ASSET = { + // this is the metadata for the new asset to register metadata: { decimals: 6, name: "USD Coin", @@ -35,19 +36,21 @@ const NEW_ASSET = { }, additional: { feePerSecond: 11888560, coingeckoId: "usd-coin" } }, + // adds `DexGeneral` pools (uniswap v2) for the asset pools: [ { token1: { Token: "INTR" }, dexFees: 100, }, ], + // adds a market to the `Loans` pallet market: { collateralFactor: 650000, // 65% liquidationThreshold: 870000, // 87% reserveFactor: 100000, // 10% closeFactor: 500000, // 50% liquidateIncentive: "1100000000000000000", // 110% - liquidateIncentiveReservedFactor: 25000, + liquidateIncentiveReservedFactor: 0, rateModel: { Jump: { baseRate: 0, @@ -62,6 +65,7 @@ const NEW_ASSET = { lendTokenId: { LendToken: 5 }, // NOTE: make sure this is free supplyIncentivesPerBlock: 0 }, + // adds vault thresholds for asset vaultParams: { wrappedCurrency: { Token: "IBTC" }, liquidationCollateral: "1050000000000000000", // 105% @@ -69,12 +73,21 @@ const NEW_ASSET = { secureCollateral: "1550000000000000000", // 155% minimumCollateral: "1550000000", // 1550 USDC systemCollateralCeiling: "2000000000000", // 2,000,000 USDC + }, + // adds vault thresholds for `Loans` asset + lendVaultParams: { + wrappedCurrency: { Token: "IBTC" }, + liquidationCollateral: "1050000000000000000", // 105% + premiumRedeem: "1150000000000000000", // 115% + secureCollateral: "1550000000000000000", // 155% + minimumCollateral: "77500000000", // 1550 USDC = 77,500 qUSDC + systemCollateralCeiling: "75000000000000", // 1,500,000 USDC = 75,000,000 qUSDC } }; function vaultRegistryCalls( api: ApiPromise, - collateralCurrency: { ForeignAsset: number }, + collateralCurrency: { ForeignAsset: number } | { LendToken: number }, ) { const { wrappedCurrency, @@ -115,15 +128,16 @@ async function main(): Promise { paraApi.tx.dexGeneral.createPair(currencyId, pool.token1, pool.dexFees) )) - allCalls.push( - ...[ - paraApi.tx.loans.addMarket(currencyId, NEW_ASSET.market), - paraApi.tx.loans.activateMarket(currencyId) - ] - ); + allCalls.push(...[ + paraApi.tx.loans.addMarket(currencyId, NEW_ASSET.market), + paraApi.tx.loans.activateMarket(currencyId) + ]); allCalls.push(...vaultRegistryCalls(paraApi, currencyId)); + const lendCurrencyId = NEW_ASSET.market.lendTokenId; + allCalls.push(...vaultRegistryCalls(paraApi, lendCurrencyId)); + const batched = paraApi.tx.utility.batchAll(allCalls); const title = `Register ${NEW_ASSET.metadata.symbol}`; From b7cb87cfb840fc3c92ecabe49f43ad7667503871 Mon Sep 17 00:00:00 2001 From: Gregory Hill Date: Mon, 12 Feb 2024 13:35:00 +0000 Subject: [PATCH 4/4] use lend vault params Signed-off-by: Gregory Hill --- scripts/register-asset.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/register-asset.ts b/scripts/register-asset.ts index 562f2eaac..a318e73fe 100644 --- a/scripts/register-asset.ts +++ b/scripts/register-asset.ts @@ -88,6 +88,7 @@ const NEW_ASSET = { function vaultRegistryCalls( api: ApiPromise, collateralCurrency: { ForeignAsset: number } | { LendToken: number }, + vaultParams: any, ) { const { wrappedCurrency, @@ -96,7 +97,7 @@ function vaultRegistryCalls( secureCollateral, minimumCollateral, systemCollateralCeiling - } = NEW_ASSET.vaultParams; + } = vaultParams; const currencyPair = { collateral: collateralCurrency, wrapped: wrappedCurrency, @@ -133,10 +134,10 @@ async function main(): Promise { paraApi.tx.loans.activateMarket(currencyId) ]); - allCalls.push(...vaultRegistryCalls(paraApi, currencyId)); + allCalls.push(...vaultRegistryCalls(paraApi, currencyId, NEW_ASSET.vaultParams)); const lendCurrencyId = NEW_ASSET.market.lendTokenId; - allCalls.push(...vaultRegistryCalls(paraApi, lendCurrencyId)); + allCalls.push(...vaultRegistryCalls(paraApi, lendCurrencyId, NEW_ASSET.lendVaultParams)); const batched = paraApi.tx.utility.batchAll(allCalls);