Skip to content

Commit df613fa

Browse files
committed
remove forked mainnet
1 parent 14ecafd commit df613fa

1 file changed

Lines changed: 60 additions & 60 deletions

File tree

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#test_fork(network: "mainnet-fork", height: 142528994)
2-
31
import Test
42
import BlockchainHelpers
53

@@ -10,11 +8,8 @@ import "FlowALPEvents"
108

119
import "test_helpers.cdc"
1210

13-
access(all) let MAINNET_PROTOCOL_ACCOUNT = Test.getAccount(MAINNET_PROTOCOL_ACCOUNT_ADDRESS)
14-
access(all) let MAINNET_USDF_HOLDER = Test.getAccount(MAINNET_USDF_HOLDER_ADDRESS)
15-
access(all) let MAINNET_WETH_HOLDER = Test.getAccount(MAINNET_WETH_HOLDER_ADDRESS)
16-
access(all) let MAINNET_WBTC_HOLDER = Test.getAccount(MAINNET_WBTC_HOLDER_ADDRESS)
17-
access(all) let MAINNET_FLOW_HOLDER = Test.getAccount(MAINNET_FLOW_HOLDER_ADDRESS)
11+
// Test MOET storage path for testing environment
12+
access(all) let TEST_MOET_STORAGE_PATH = /storage/moetTokenVault_0x0000000000000007
1813

1914
access(all) var snapshot: UInt64 = 0
2015

@@ -39,12 +34,12 @@ access(all)
3934
fun setup() {
4035
deployContracts()
4136

42-
createAndStorePool(signer: MAINNET_PROTOCOL_ACCOUNT, defaultTokenIdentifier: MAINNET_MOET_TOKEN_ID, beFailed: false)
43-
setMockOraclePrice(signer: MAINNET_PROTOCOL_ACCOUNT, forTokenIdentifier: MAINNET_FLOW_TOKEN_ID, price: 1.0)
37+
createAndStorePool(signer: PROTOCOL_ACCOUNT, defaultTokenIdentifier: MOET_TOKEN_IDENTIFIER, beFailed: false)
38+
setMockOraclePrice(signer: PROTOCOL_ACCOUNT, forTokenIdentifier: FLOW_TOKEN_IDENTIFIER, price: 1.0)
4439

4540
addSupportedTokenKinkCurve(
46-
signer: MAINNET_PROTOCOL_ACCOUNT,
47-
tokenTypeIdentifier: MAINNET_FLOW_TOKEN_ID,
41+
signer: PROTOCOL_ACCOUNT,
42+
tokenTypeIdentifier: FLOW_TOKEN_IDENTIFIER,
4843
collateralFactor: 0.8,
4944
borrowFactor: 0.9,
5045
optimalUtilization: flowOptimalUtilization,
@@ -57,22 +52,22 @@ fun setup() {
5752

5853
// set MOET to use a FixedRateInterestCurve at 4% APY.
5954
setInterestCurveFixed(
60-
signer: MAINNET_PROTOCOL_ACCOUNT,
61-
tokenTypeIdentifier: MAINNET_MOET_TOKEN_ID,
55+
signer: PROTOCOL_ACCOUNT,
56+
tokenTypeIdentifier: MOET_TOKEN_IDENTIFIER,
6257
yearlyRate: moetFixedRate
6358
)
6459

6560
let res = setInsuranceSwapper(
66-
signer: MAINNET_PROTOCOL_ACCOUNT,
67-
swapperInTypeIdentifier: MAINNET_FLOW_TOKEN_ID,
68-
swapperOutTypeIdentifier: MAINNET_MOET_TOKEN_ID,
61+
signer: PROTOCOL_ACCOUNT,
62+
swapperInTypeIdentifier: FLOW_TOKEN_IDENTIFIER,
63+
swapperOutTypeIdentifier: MOET_TOKEN_IDENTIFIER,
6964
priceRatio: 1.0,
7065
)
7166
Test.expect(res, Test.beSucceeded())
7267

7368
let setInsRes = setInsuranceRate(
74-
signer: MAINNET_PROTOCOL_ACCOUNT,
75-
tokenTypeIdentifier: MAINNET_FLOW_TOKEN_ID,
69+
signer: PROTOCOL_ACCOUNT,
70+
tokenTypeIdentifier: FLOW_TOKEN_IDENTIFIER,
7671
insuranceRate: 0.001,
7772
)
7873
Test.expect(setInsRes, Test.beSucceeded())
@@ -88,8 +83,8 @@ fun test_extreme_utilization() {
8883
safeReset()
8984

9085
setInterestCurveKink(
91-
signer: MAINNET_PROTOCOL_ACCOUNT,
92-
tokenTypeIdentifier: MAINNET_FLOW_TOKEN_ID,
86+
signer: PROTOCOL_ACCOUNT,
87+
tokenTypeIdentifier: FLOW_TOKEN_IDENTIFIER,
9388
optimalUtilization: flowOptimalUtilization,
9489
baseRate: flowBaseRate,
9590
slope1: flowSlope1,
@@ -98,23 +93,25 @@ fun test_extreme_utilization() {
9893

9994
// create Flow LP with 2000 FLOW
10095
let FLOWAmount = 2000.0
96+
let flowLp = Test.createAccount()
97+
transferFlowTokens(to: flowLp, amount: FLOWAmount)
10198

102-
createPosition(admin: MAINNET_PROTOCOL_ACCOUNT, signer: MAINNET_FLOW_HOLDER, amount: FLOWAmount, vaultStoragePath: FLOW_VAULT_STORAGE_PATH, pushToDrawDownSink: false)
99+
createPosition(admin: PROTOCOL_ACCOUNT, signer: flowLp, amount: FLOWAmount, vaultStoragePath: FLOW_VAULT_STORAGE_PATH, pushToDrawDownSink: false)
103100
let lpDepositPid = getLastPositionId()
104101

105102
// create borrower with MOET collateral
106103
let borrower = Test.createAccount()
107104
setupMoetVault(borrower, beFailed: false)
108-
mintMoet(signer: MAINNET_PROTOCOL_ACCOUNT, to: borrower.address, amount: 10_000.0, beFailed: false)
105+
mintMoet(signer: PROTOCOL_ACCOUNT, to: borrower.address, amount: 10_000.0, beFailed: false)
109106

110-
createPosition(admin: MAINNET_PROTOCOL_ACCOUNT, signer: borrower, amount: 10_000.0, vaultStoragePath: MAINNET_MOET_STORAGE_PATH, pushToDrawDownSink: false)
107+
createPosition(admin: PROTOCOL_ACCOUNT, signer: borrower, amount: 10_000.0, vaultStoragePath: TEST_MOET_STORAGE_PATH, pushToDrawDownSink: false)
111108

112109
let borrowerPid = getLastPositionId()
113110
// borrow 1800 FLOW (90% of 2000 FLOW credit)
114111
borrowFromPosition(
115112
signer: borrower,
116113
positionId: borrowerPid,
117-
tokenTypeIdentifier: MAINNET_FLOW_TOKEN_ID,
114+
tokenTypeIdentifier: FLOW_TOKEN_IDENTIFIER,
118115
vaultStoragePath: FLOW_VAULT_STORAGE_PATH,
119116
amount: 1800.0,
120117
beFailed: false
@@ -161,7 +158,7 @@ fun test_extreme_utilization() {
161158
// depends on block timestamps, which can differ slightly between test runs.
162159
// A larger, time-aware tolerance is required.
163160
let tolerance = 0.00001
164-
var diff = expectedFLOWGrowthRate > FLOWGrowthRate
161+
var diff = expectedFLOWGrowthRate > FLOWGrowthRate
165162
? expectedFLOWGrowthRate - FLOWGrowthRate
166163
: FLOWGrowthRate - expectedFLOWGrowthRate
167164
Test.assert(diff < tolerance, message: "Expected FLOW debt growth rate to be \(expectedFLOWGrowthRate) but got \(FLOWGrowthRate)")
@@ -179,8 +176,8 @@ fun test_zero_credit_balance() {
179176
setupMoetVault(borrower, beFailed: false)
180177

181178
let MOETAmount = 10_000.0
182-
mintMoet(signer: MAINNET_PROTOCOL_ACCOUNT, to: borrower.address, amount: MOETAmount, beFailed: false)
183-
createPosition(admin: MAINNET_PROTOCOL_ACCOUNT, signer: borrower, amount: MOETAmount, vaultStoragePath: MAINNET_MOET_STORAGE_PATH, pushToDrawDownSink: false)
179+
mintMoet(signer: PROTOCOL_ACCOUNT, to: borrower.address, amount: MOETAmount, beFailed: false)
180+
createPosition(admin: PROTOCOL_ACCOUNT, signer: borrower, amount: MOETAmount, vaultStoragePath: TEST_MOET_STORAGE_PATH, pushToDrawDownSink: false)
184181

185182
// no Flow LP is created — pool has zero FLOW liquidity
186183

@@ -189,7 +186,7 @@ fun test_zero_credit_balance() {
189186

190187
let borrowRes = _executeTransaction(
191188
"./transactions/position-manager/borrow_from_position.cdc",
192-
[pid, MAINNET_FLOW_TOKEN_ID, FLOW_VAULT_STORAGE_PATH, 100.0],
189+
[pid, FLOW_TOKEN_IDENTIFIER, FLOW_VAULT_STORAGE_PATH, 100.0],
193190
borrower
194191
)
195192
Test.expect(borrowRes, Test.beFailed())
@@ -242,20 +239,15 @@ fun test_zero_credit_balance() {
242239
// add FLOW liquidity
243240
let FLOWAmount = 5000.0
244241
let flowLp = Test.createAccount()
245-
transferFungibleTokens(
246-
tokenIdentifier: MAINNET_FLOW_TOKEN_ID,
247-
from: MAINNET_FLOW_HOLDER,
248-
to: flowLp,
249-
amount: FLOWAmount
250-
)
251-
createPosition(admin: MAINNET_PROTOCOL_ACCOUNT, signer: flowLp, amount: FLOWAmount, vaultStoragePath: FLOW_VAULT_STORAGE_PATH, pushToDrawDownSink: false)
242+
transferFlowTokens(to: flowLp, amount: FLOWAmount)
243+
createPosition(admin: PROTOCOL_ACCOUNT, signer: flowLp, amount: FLOWAmount, vaultStoragePath: FLOW_VAULT_STORAGE_PATH, pushToDrawDownSink: false)
252244
let lpPid = getLastPositionId()
253245

254246
// borrow FLOW (Flow LP deposited 5000.0 FLOW, liquidity now available)
255247
borrowFromPosition(
256248
signer: borrower,
257249
positionId: pid,
258-
tokenTypeIdentifier: MAINNET_FLOW_TOKEN_ID,
250+
tokenTypeIdentifier: FLOW_TOKEN_IDENTIFIER,
259251
vaultStoragePath: FLOW_VAULT_STORAGE_PATH,
260252
amount: 100.0,
261253
beFailed: false
@@ -322,8 +314,8 @@ fun test_empty_pool() {
322314
// create Flow LP only — no borrowers
323315
let flowLp = Test.createAccount()
324316
let FLOWAmount = 10000.0
325-
transferFungibleTokens(tokenIdentifier: MAINNET_FLOW_TOKEN_ID, from: MAINNET_FLOW_HOLDER, to: flowLp, amount: FLOWAmount)
326-
createPosition(admin: MAINNET_PROTOCOL_ACCOUNT, signer: flowLp, amount: FLOWAmount, vaultStoragePath: FLOW_VAULT_STORAGE_PATH, pushToDrawDownSink: false)
317+
transferFlowTokens(to: flowLp, amount: FLOWAmount)
318+
createPosition(admin: PROTOCOL_ACCOUNT, signer: flowLp, amount: FLOWAmount, vaultStoragePath: FLOW_VAULT_STORAGE_PATH, pushToDrawDownSink: false)
327319

328320
let lpPid = getLastPositionId()
329321

@@ -336,7 +328,7 @@ fun test_empty_pool() {
336328
Test.commitBlock()
337329

338330
// FLOW rate calculation (KinkInterestCurve)
339-
// baseRate:0
331+
// baseRate:0
340332
// debitBalance:0
341333
//
342334
// debitRate = (if no debt, debitRate = base rate) = 0
@@ -348,15 +340,15 @@ fun test_empty_pool() {
348340
// create a borrower to trigger utilization
349341
let borrower = Test.createAccount()
350342
setupMoetVault(borrower, beFailed: false)
351-
mintMoet(signer: MAINNET_PROTOCOL_ACCOUNT, to: borrower.address, amount: 10_000.0, beFailed: false)
343+
mintMoet(signer: PROTOCOL_ACCOUNT, to: borrower.address, amount: 10_000.0, beFailed: false)
352344

353-
createPosition(admin: MAINNET_PROTOCOL_ACCOUNT, signer: borrower, amount: 10_000.0, vaultStoragePath: MAINNET_MOET_STORAGE_PATH, pushToDrawDownSink: false)
345+
createPosition(admin: PROTOCOL_ACCOUNT, signer: borrower, amount: 10_000.0, vaultStoragePath: TEST_MOET_STORAGE_PATH, pushToDrawDownSink: false)
354346

355347
let borrowerPid= getLastPositionId()
356348
borrowFromPosition(
357349
signer: borrower,
358350
positionId: borrowerPid,
359-
tokenTypeIdentifier: MAINNET_FLOW_TOKEN_ID,
351+
tokenTypeIdentifier: FLOW_TOKEN_IDENTIFIER,
360352
vaultStoragePath: FLOW_VAULT_STORAGE_PATH,
361353
amount: 2_000.0,
362354
beFailed: false
@@ -403,22 +395,24 @@ fun test_kink_point_transition() {
403395
safeReset()
404396

405397
setInterestCurveKink(
406-
signer: MAINNET_PROTOCOL_ACCOUNT,
407-
tokenTypeIdentifier: MAINNET_FLOW_TOKEN_ID,
398+
signer: PROTOCOL_ACCOUNT,
399+
tokenTypeIdentifier: FLOW_TOKEN_IDENTIFIER,
408400
optimalUtilization: flowOptimalUtilization,
409401
baseRate: flowBaseRate,
410402
slope1: flowSlope1,
411403
slope2: flowSlope2
412404
)
413405

414406
// create LP with 10000 FLOW
415-
createPosition(admin: MAINNET_PROTOCOL_ACCOUNT, signer: MAINNET_FLOW_HOLDER, amount: 10000.0, vaultStoragePath: FLOW_VAULT_STORAGE_PATH, pushToDrawDownSink: false)
407+
let flowLp = Test.createAccount()
408+
transferFlowTokens(to: flowLp, amount: 10000.0)
409+
createPosition(admin: PROTOCOL_ACCOUNT, signer: flowLp, amount: 10000.0, vaultStoragePath: FLOW_VAULT_STORAGE_PATH, pushToDrawDownSink: false)
416410

417411
// create borrower with large MOET collateral
418412
let borrower = Test.createAccount()
419413
setupMoetVault(borrower, beFailed: false)
420-
mintMoet(signer: MAINNET_PROTOCOL_ACCOUNT, to: borrower.address, amount: 100_000.0, beFailed: false)
421-
createPosition(admin: MAINNET_PROTOCOL_ACCOUNT, signer: borrower, amount: 100_000.0, vaultStoragePath: MAINNET_MOET_STORAGE_PATH, pushToDrawDownSink: false)
414+
mintMoet(signer: PROTOCOL_ACCOUNT, to: borrower.address, amount: 100_000.0, beFailed: false)
415+
createPosition(admin: PROTOCOL_ACCOUNT, signer: borrower, amount: 100_000.0, vaultStoragePath: TEST_MOET_STORAGE_PATH, pushToDrawDownSink: false)
422416

423417
let borrowerPid = getLastPositionId()
424418

@@ -430,7 +424,7 @@ fun test_kink_point_transition() {
430424
borrowFromPosition(
431425
signer: borrower,
432426
positionId: borrowerPid,
433-
tokenTypeIdentifier: MAINNET_FLOW_TOKEN_ID,
427+
tokenTypeIdentifier: FLOW_TOKEN_IDENTIFIER,
434428
vaultStoragePath: FLOW_VAULT_STORAGE_PATH,
435429
amount: 4500.0,
436430
beFailed: false
@@ -470,22 +464,24 @@ fun test_long_time_period_accrual() {
470464
safeReset()
471465

472466
// create LP with 10000 FLOW
473-
createPosition(admin: MAINNET_PROTOCOL_ACCOUNT, signer: MAINNET_FLOW_HOLDER, amount: 10000.0, vaultStoragePath: FLOW_VAULT_STORAGE_PATH, pushToDrawDownSink: false)
467+
let flowLp = Test.createAccount()
468+
transferFlowTokens(to: flowLp, amount: 10000.0)
469+
createPosition(admin: PROTOCOL_ACCOUNT, signer: flowLp, amount: 10000.0, vaultStoragePath: FLOW_VAULT_STORAGE_PATH, pushToDrawDownSink: false)
474470
let lpPid = getLastPositionId()
475471

476472
// create borrower
477473
let borrower = Test.createAccount()
478474
setupMoetVault(borrower, beFailed: false)
479-
mintMoet(signer: MAINNET_PROTOCOL_ACCOUNT, to: borrower.address, amount: 100_000.0, beFailed: false)
480-
createPosition(admin: MAINNET_PROTOCOL_ACCOUNT, signer: borrower, amount: 100_000.0, vaultStoragePath: MAINNET_MOET_STORAGE_PATH, pushToDrawDownSink: false)
475+
mintMoet(signer: PROTOCOL_ACCOUNT, to: borrower.address, amount: 100_000.0, beFailed: false)
476+
createPosition(admin: PROTOCOL_ACCOUNT, signer: borrower, amount: 100_000.0, vaultStoragePath: TEST_MOET_STORAGE_PATH, pushToDrawDownSink: false)
481477

482478
let borrowerPid = getLastPositionId()
483479

484480
// borrow 2000 FLOW
485481
borrowFromPosition(
486482
signer: borrower,
487483
positionId: borrowerPid,
488-
tokenTypeIdentifier: MAINNET_FLOW_TOKEN_ID,
484+
tokenTypeIdentifier: FLOW_TOKEN_IDENTIFIER,
489485
vaultStoragePath: FLOW_VAULT_STORAGE_PATH,
490486
amount: 2000.0,
491487
beFailed: false
@@ -537,7 +533,8 @@ fun test_long_time_period_accrual() {
537533
// 11-year debt growth = perSecondRate^(31_557_600 * 11) - 1
538534
// FLOW debit 11-year growth = (1 + 0.017777778 / 31_557_600)^(31_557_600*11) - 1 = 0.21598635
539535
let expectedFLOWDebt10YearsGrowth = 0.21598635
540-
Test.assertEqual(expectedFLOWDebt10YearsGrowth, FLOWTotalGrowthRate)
536+
Test.assert(equalWithinVariance(expectedFLOWDebt10YearsGrowth, FLOWTotalGrowthRate, DEFAULT_UFIX_VARIANCE),
537+
message: "Expected FLOW debt 11-year growth to be ~\(expectedFLOWDebt10YearsGrowth), but got \(FLOWTotalGrowthRate)")
541538
}
542539

543540
// =============================================================================
@@ -548,20 +545,22 @@ fun test_time_jump_scenarios() {
548545
safeReset()
549546

550547
// set up LP and borrower
551-
createPosition(admin: MAINNET_PROTOCOL_ACCOUNT, signer: MAINNET_FLOW_HOLDER, amount: 10000.0, vaultStoragePath: FLOW_VAULT_STORAGE_PATH, pushToDrawDownSink: false)
548+
let flowLp = Test.createAccount()
549+
transferFlowTokens(to: flowLp, amount: 10000.0)
550+
createPosition(admin: PROTOCOL_ACCOUNT, signer: flowLp, amount: 10000.0, vaultStoragePath: FLOW_VAULT_STORAGE_PATH, pushToDrawDownSink: false)
552551

553552
let borrower = Test.createAccount()
554553
setupMoetVault(borrower, beFailed: false)
555-
mintMoet(signer: MAINNET_PROTOCOL_ACCOUNT, to: borrower.address, amount: 50_000.0, beFailed: false)
556-
createPosition(admin: MAINNET_PROTOCOL_ACCOUNT, signer: borrower, amount: 50_000.0, vaultStoragePath: MAINNET_MOET_STORAGE_PATH, pushToDrawDownSink: false)
554+
mintMoet(signer: PROTOCOL_ACCOUNT, to: borrower.address, amount: 50_000.0, beFailed: false)
555+
createPosition(admin: PROTOCOL_ACCOUNT, signer: borrower, amount: 50_000.0, vaultStoragePath: TEST_MOET_STORAGE_PATH, pushToDrawDownSink: false)
557556

558557
let borrowerPid = getLastPositionId()
559558

560559
// borrow 5000 FLOW
561560
borrowFromPosition(
562561
signer: borrower,
563562
positionId: borrowerPid,
564-
tokenTypeIdentifier: MAINNET_FLOW_TOKEN_ID,
563+
tokenTypeIdentifier: FLOW_TOKEN_IDENTIFIER,
565564
vaultStoragePath: FLOW_VAULT_STORAGE_PATH,
566565
amount: 5000.0,
567566
beFailed: false
@@ -597,7 +596,8 @@ fun test_time_jump_scenarios() {
597596
// dailyGrowth = perSecondRate^86400 - 1
598597
// FLOW debit daily growth = (1 + 0.31272727 / 31557600)^86400 - 1 = 0.00085660
599598
let expectedFLOWDebtDailyGrowth = 0.00085660
600-
Test.assert(equalWithinVariance(expectedFLOWDebtDailyGrowth, FLOWDebtDailyGrowth, DEFAULT_UFIX_VARIANCE),
599+
let interestVariance = 0.00001 // slightly larger variance for interest calculations
600+
Test.assert(equalWithinVariance(expectedFLOWDebtDailyGrowth, FLOWDebtDailyGrowth, interestVariance),
601601
message: "Expected FLOW debt growth rate to be ~\(expectedFLOWDebtDailyGrowth), but got \(FLOWDebtDailyGrowth)")
602602

603603
// test longer period (7 days) to verify no overflow in calculation
@@ -616,6 +616,6 @@ fun test_time_jump_scenarios() {
616616
// weeklyGrowth = perSecondRate^604800 - 1
617617
// FLOW debit weekly growth = (1 + 0.31272727272 / 31_557_600)^604800 - 1 = 0.00601143
618618
let expectedFLOWDebtWeeklyGrowth = 0.00601143
619-
Test.assert(equalWithinVariance(expectedFLOWDebtWeeklyGrowth, FLOWDebtWeeklyGrowth, DEFAULT_UFIX_VARIANCE),
619+
Test.assert(equalWithinVariance(expectedFLOWDebtWeeklyGrowth, FLOWDebtWeeklyGrowth, interestVariance),
620620
message: "Expected FLOW debt growth rate to be ~\(expectedFLOWDebtWeeklyGrowth), but got \(FLOWDebtWeeklyGrowth)")
621-
}
621+
}

0 commit comments

Comments
 (0)