Skip to content

Commit 8b267c2

Browse files
author
Iztok
committed
changed auto transfer to cv algorithm and minimum cv transfer size setting
1 parent ad7bcae commit 8b267c2

16 files changed

+48
-10
lines changed

packages/fasset-bots-core/run-config/coston-bot.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"returnFromCVRatio": 0.3,
5858
"targetTransferToCVRatio": 0.4,
5959
"targetReturnFromCVRatio": 0.6,
60+
"minimumTransferToCVSize": 0.2,
6061
"useAutomaticCoreVaultTransferAndReturn": true
6162
},
6263
"FSimCoinX": {
@@ -67,6 +68,7 @@
6768
"returnFromCVRatio": 0.3,
6869
"targetTransferToCVRatio": 0.4,
6970
"targetReturnFromCVRatio": 0.6,
71+
"minimumTransferToCVSize": 0.2,
7072
"useAutomaticCoreVaultTransferAndReturn": true
7173
},
7274
"FTestBTC": {
@@ -77,6 +79,7 @@
7779
"returnFromCVRatio": 0.3,
7880
"targetTransferToCVRatio": 0.4,
7981
"targetReturnFromCVRatio": 0.6,
82+
"minimumTransferToCVSize": 0.2,
8083
"useAutomaticCoreVaultTransferAndReturn": true
8184
},
8285
"FTestDOGE": {
@@ -87,6 +90,7 @@
8790
"returnFromCVRatio": 0.3,
8891
"targetTransferToCVRatio": 0.4,
8992
"targetReturnFromCVRatio": 0.6,
93+
"minimumTransferToCVSize": 0.2,
9094
"useAutomaticCoreVaultTransferAndReturn": true
9195
}
9296
}

packages/fasset-bots-core/run-config/coston2-bot.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"returnFromCVRatio": 0.3,
5858
"targetTransferToCVRatio": 0.4,
5959
"targetReturnFromCVRatio": 0.6,
60+
"minimumTransferToCVSize": 0.2,
6061
"useAutomaticCoreVaultTransferAndReturn": true
6162
}
6263
}

packages/fasset-bots-core/run-config/flare-bot.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"returnFromCVRatio": 0.3,
5656
"targetTransferToCVRatio": 0.4,
5757
"targetReturnFromCVRatio": 0.6,
58+
"minimumTransferToCVSize": 0.2,
5859
"useAutomaticCoreVaultTransferAndReturn": false
5960
}
6061
}

packages/fasset-bots-core/run-config/schema/bot-config-override.schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
"pattern": "^[0-9]+(\\.[0-9]+)?$",
1919
"type": "string"
2020
},
21+
"minimumTransferToCVSize": {
22+
"description": "Minimum transfer to CV amount (as share of the total minting capacity).",
23+
"type": "number"
24+
},
2125
"recommendedOwnerBalance": {
2226
"description": "The amount of underlying currency on owner's underlying address, below which an alert is triggered.",
2327
"pattern": "^[0-9]+(\\.[0-9]+)?$",
@@ -47,6 +51,7 @@
4751
"required": [
4852
"feeSafetyFactorPerKB",
4953
"minimumFreeUnderlyingBalance",
54+
"minimumTransferToCVSize",
5055
"recommendedOwnerBalance",
5156
"returnFromCVRatio",
5257
"targetReturnFromCVRatio",
@@ -426,6 +431,10 @@
426431
"pattern": "^[0-9]+(\\.[0-9]+)?$",
427432
"type": "string"
428433
},
434+
"minimumTransferToCVSize": {
435+
"description": "Minimum transfer to CV amount (as share of the total minting capacity).",
436+
"type": "number"
437+
},
429438
"recommendedOwnerBalance": {
430439
"description": "The amount of underlying currency on owner's underlying address, below which an alert is triggered.",
431440
"pattern": "^[0-9]+(\\.[0-9]+)?$",

packages/fasset-bots-core/run-config/schema/bot-config.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
"pattern": "^[0-9]+(\\.[0-9]+)?$",
1919
"type": "string"
2020
},
21+
"minimumTransferToCVSize": {
22+
"description": "Minimum transfer to CV amount (as share of the total minting capacity).",
23+
"type": "number"
24+
},
2125
"recommendedOwnerBalance": {
2226
"description": "The amount of underlying currency on owner's underlying address, below which an alert is triggered.",
2327
"pattern": "^[0-9]+(\\.[0-9]+)?$",
@@ -47,6 +51,7 @@
4751
"required": [
4852
"feeSafetyFactorPerKB",
4953
"minimumFreeUnderlyingBalance",
54+
"minimumTransferToCVSize",
5055
"recommendedOwnerBalance",
5156
"returnFromCVRatio",
5257
"targetReturnFromCVRatio",

packages/fasset-bots-core/run-config/songbird-bot.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"returnFromCVRatio": 0.3,
5656
"targetTransferToCVRatio": 0.4,
5757
"targetReturnFromCVRatio": 0.6,
58+
"minimumTransferToCVSize": 0.2,
5859
"useAutomaticCoreVaultTransferAndReturn": false
5960
}
6061
}

packages/fasset-bots-core/src/actors/AgentBot.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -671,24 +671,25 @@ export class AgentBot {
671671
const lotSize = Number(settings.lotSizeAMG) * Number(settings.assetMintingGranularityUBA);
672672
const freeLots = Number(agentInfo.freeCollateralLots);
673673
const mintedLots = Number(toBN(agentInfo.mintedUBA).divn(lotSize));
674+
const mintedOrReservedLots = Number(toBN(agentInfo.mintedUBA).add(toBN(agentInfo.reservedUBA)).divn(lotSize));
674675
const lockedLots = Number(toBN(agentInfo.mintedUBA).add(toBN(agentInfo.reservedUBA)).add(toBN(agentInfo.redeemingUBA)).divn(lotSize));
675676

676677
const totalLots = lockedLots + freeLots;
677678
if (totalLots === 0) return;
678679

679680
// transfer to CV - mintedLots must be large enough
680-
if (mintedLots / totalLots > this.agentBotSettings.transferToCVRatio) {
681+
if (mintedOrReservedLots / totalLots > this.agentBotSettings.transferToCVRatio) {
681682
const openTransfers = await this.redemption.openTransferToCoreVaultIds(rootEm);
682683
if (openTransfers.length == 0) {
683684
const target = this.agentBotSettings.targetTransferToCVRatio;
684-
// agent wants
685-
const transferLots = Math.floor(mintedLots - target * (totalLots));
686-
const transferLotsAmount = toBN(transferLots * lotSize);
685+
const requestedTransferLots = Math.floor(mintedLots - target * totalLots);
686+
const requestedTransferAmount = toBN(requestedTransferLots * lotSize);
687687
// check how much is allowed to transfer
688688
const maxAllowedToTransfer = await getMaximumTransferToCoreVault(this.context, this.agent.vaultAddress);
689689
// actual return
690-
const transferAmount = minBN(transferLotsAmount, maxAllowedToTransfer.maximumTransferUBA);
691-
if (transferAmount.gte(toBN(settings.lotSizeAMG))) {
690+
const transferAmount = minBN(requestedTransferAmount, maxAllowedToTransfer.maximumTransferUBA);
691+
const minTransferAmount = Math.floor(totalLots * lotSize * this.agentBotSettings.minimumTransferToCVSize);
692+
if (transferAmount.gte(toBN(Math.max(lotSize, minTransferAmount)))) {
692693
await this.transferToCoreVault(transferAmount);
693694
}
694695
}
@@ -699,13 +700,12 @@ export class AgentBot {
699700
const openReturns = await this.returnFromCoreVaultBot.openReturnFromCoreVaultIds(rootEm);
700701
if (openReturns.length == 0) {
701702
const target = this.agentBotSettings.targetReturnFromCVRatio;
702-
// agents wants
703-
const returnLots = Math.floor(target * (totalLots) - mintedLots);
703+
const returnLots = Math.floor(target * totalLots - mintedLots);
704704
// check how much can CV return
705705
const { 1: maxCVReturnAmount } = await this.context.assetManager.coreVaultAvailableAmount();
706-
const maxCVReturnLot = Math.floor(Number(toBN(maxCVReturnAmount).divn(lotSize)));
706+
const maxCVReturnLots = Number(toBN(maxCVReturnAmount).divn(lotSize));
707707
// actual return
708-
const returnLotsToUse = Math.min(maxCVReturnLot, returnLots)
708+
const returnLotsToUse = Math.min(maxCVReturnLots, returnLots, freeLots)
709709
if (returnLotsToUse >= 1) {
710710
await this.returnFromCoreVault(toBN(returnLotsToUse));
711711
}

packages/fasset-bots-core/src/config/BotConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export interface AgentBotSettings {
6969
returnFromCVRatio: number;
7070
targetTransferToCVRatio: number;
7171
targetReturnFromCVRatio: number;
72+
minimumTransferToCVSize: number;
7273
useAutomaticCoreVaultTransferAndReturn: boolean;
7374
}
7475

@@ -242,6 +243,7 @@ function createAgentBotSettings(agentBotSettings: AgentBotSettingsJson, fassetSe
242243
returnFromCVRatio: Number(fassetSettings.returnFromCVRatio),
243244
targetTransferToCVRatio: Number(fassetSettings.targetTransferToCVRatio),
244245
targetReturnFromCVRatio: Number(fassetSettings.targetReturnFromCVRatio),
246+
minimumTransferToCVSize: Number(fassetSettings.minimumTransferToCVSize),
245247
useAutomaticCoreVaultTransferAndReturn: fassetSettings.useAutomaticCoreVaultTransferAndReturn
246248
}
247249
}

packages/fasset-bots-core/src/config/config-files/BotConfigFile.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ export interface AgentBotFassetSettingsJson {
146146
*/
147147
targetReturnFromCVRatio: number;
148148

149+
/**
150+
* Minimum transfer to CV amount (as share of the total minting capacity).
151+
*/
152+
minimumTransferToCVSize: number;
153+
149154
/**
150155
* If true, the bot will automatically manage CoreVault transfers and returns
151156
* based on `targetTransferToCVRatio` and `targetReturnFromCVRatio`.

packages/fasset-bots-core/test-hardhat/integration/runner-and-commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ describe("Toplevel runner and commands integration test", () => {
9292
returnFromCVRatio: 0.3,
9393
targetTransferToCVRatio: 0.4,
9494
targetReturnFromCVRatio: 0.6,
95+
minimumTransferToCVSize: 0.2,
9596
useAutomaticCoreVaultTransferAndReturn: true,
9697
};
9798

0 commit comments

Comments
 (0)