Skip to content

Commit 695b6c3

Browse files
revert UpdatePrices value bump (#733)
* revert updatePrices value bamp * bump contractversions * accept multiple previous versions on migrate function and upgradeable tests * address pr comments * remove unused version constants
1 parent 69a3617 commit 695b6c3

13 files changed

Lines changed: 227 additions & 194 deletions

File tree

contracts/contracts/ccip/fee_quoter/contract.tolk

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import "../../lib/math";
1616
import "../router/messages"
1717
import "../ccipsend_executor/messages"
1818

19-
const CONTRACT_VERSION_PREV = "1.6.0";
20-
const CONTRACT_VERSION = "1.6.1";
19+
const CONTRACT_VERSION = "1.6.2";
2120
const RESERVE = ton("1");
2221

2322
fun onInternalMessage(in: InMessage) {
@@ -662,13 +661,19 @@ get fun reserve(): coins {
662661
@method_id(1000)
663662
fun migrate(storage: cell, version: slice): cell {
664663
val NEW_THRESHOLD = 24 * 60 * 60; // 86400 seconds = 24 hours
665-
666-
assert (version.bitsEqual(CONTRACT_VERSION_PREV)) throw Upgradeable_Error.VersionMismatch;
664+
requireSupportedVersion(version);
667665
var st = Storage.fromCell(storage);
668-
st.tokenPriceStalenessThreshold = NEW_THRESHOLD;
669-
666+
st.tokenPriceStalenessThreshold = NEW_THRESHOLD;
670667
return st.toCell();
671668
}
672669

670+
fun requireSupportedVersion(version: slice) {
671+
assert (
672+
version.bitsEqual("1.6.0")
673+
|| version.bitsEqual("1.6.1")
674+
)
675+
throw Upgradeable_Error.VersionMismatch;
676+
}
677+
673678
@method_id(1001)
674679
fun version(): slice { return CONTRACT_VERSION; }

contracts/contracts/ccip/fee_quoter/messages.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,5 @@ fun FeeQuoter_Costs.GetValidatedFee(): int {
8080

8181
fun FeeQuoter_Costs.updatePrices(): int {
8282
// when we support token transfers the message value amount should depend on the quantity of supported tokens
83-
return ton("0.03");
83+
return ton("0.01");
8484
}

contracts/contracts/ccip/offramp/contract.tolk

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ import "types"
2525
import "storage"
2626
import "events"
2727

28-
const CONTRACT_VERSION_PREV = "1.6.0";
29-
const CONTRACT_VERSION = "1.6.1";
28+
const CONTRACT_VERSION = "1.6.2";
3029
const RESERVE = ton("5");
3130
const MIN_GASLIMIT = ton("0.025");
3231

@@ -238,10 +237,18 @@ fun onUpgrade(msg: Upgradeable_Upgrade) {
238237

239238
@method_id(1000)
240239
fun migrate(storage: cell, version: slice): cell {
241-
assert (version.bitsEqual(CONTRACT_VERSION_PREV)) throw Upgradeable_Error.VersionMismatch;
240+
requireSupportedVersion(version);
242241
return storage;
243242
}
244243

244+
fun requireSupportedVersion(version: slice) {
245+
assert (
246+
version.bitsEqual("1.6.0")
247+
|| version.bitsEqual("1.6.1")
248+
)
249+
throw Upgradeable_Error.VersionMismatch;
250+
}
251+
245252
@method_id(1001)
246253
fun version(): slice { return CONTRACT_VERSION; }
247254

contracts/default.nix

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,32 @@
8888
cp -r * $out/
8989
'';
9090

91+
meta = with pkgs.lib; {
92+
description = "Chainlink TON smart contracts";
93+
94+
# TODO: update to MIT after March 12, 2029 as per LICENSE file
95+
license = licenses.bsl11;
96+
97+
# TODO: update to contracts project-specific tag
98+
changelog = "https://github.com/smartcontractkit/chainlink-ton/releases/tag/v${finalAttrs.version}";
99+
};
100+
});
101+
contracts_1_6_1 = pkgs.stdenv.mkDerivation (finalAttrs: rec {
102+
pname = "chainlink-contracts-ton";
103+
104+
src = builtins.fetchurl {
105+
url = "https://github.com/smartcontractkit/chainlink-ton/releases/download/contracts/${finalAttrs.version}/contracts-${finalAttrs.version}.tar.gz";
106+
sha256 = "sha256:0j9f7pxqamqj1p3zrfa9kggx15j80p5whv514w2wi1dp5zhmpfs1";
107+
};
108+
version = "1.6.1";
109+
sourceRoot = "."; # pin source root to avoid issues with unpacker (produced multiple directories)
110+
111+
skipBuild = true;
112+
installPhase = ''
113+
mkdir -p $out
114+
cp -r * $out/
115+
'';
116+
91117
meta = with pkgs.lib; {
92118
description = "Chainlink TON smart contracts";
93119

@@ -105,6 +131,7 @@ in {
105131
contracts = pkgs.callPackage ./shell.nix {
106132
inherit pkgs;
107133
contracts_1_6 = packages.contracts_1_6;
134+
contracts_1_6_1 = packages.contracts_1_6_1;
108135
jetton-contracts = packages.contracts-jetton-func;
109136
inherit oplint;
110137
};

contracts/shell.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
pkgs,
44
lib,
55
contracts_1_6,
6+
contracts_1_6_1,
67
jetton-contracts,
78
oplint,
89
}:
@@ -27,10 +28,12 @@ pkgs.mkShell {
2728

2829
PATH_CONTRACTS_JETTON = "${jetton-contracts}/lib/node_modules/jetton/build/";
2930
PATH_CONTRACTS_1_6 = "${contracts_1_6}"; # Notice: loaded from GH release, artifacts in root of the package
31+
PATH_CONTRACTS_1_6_1 = "${contracts_1_6_1}"; # Notice: loaded from GH release, artifacts in root of the package
3032

3133
shellHook = ''
3234
echo "Loaded TVM contracts at following paths:"
3335
echo " - CCIP 1.6.0: (env:PATH_CONTRACTS_1_6) $PATH_CONTRACTS_1_6"
36+
echo " - CCIP 1.6.1: (env:PATH_CONTRACTS_1_6_1) $PATH_CONTRACTS_1_6_1"
3437
echo " - Jetton: (env:PATH_CONTRACTS_JETTON) $PATH_CONTRACTS_JETTON"
3538
'';
3639
}

contracts/tests/ccip/OffRamp.spec.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,24 @@ describe('OffRamp - Withdrawable Tests', () => {
172172

173173
describe('OffRamp - Upgrade Tests', () => {
174174
class OffRamp extends of.OffRamp {}
175-
class OffRampPrev extends of.OffRamp {
176-
static code(): Promise<Cell> {
177-
return contractCode.ccip.release_1_6_0('OffRamp')
178-
}
179-
}
175+
176+
const codeLoaders = {
177+
'1.6.0': () => contractCode.ccip.release_1_6_0('OffRamp'),
178+
'1.6.1': () => contractCode.ccip.release_1_6_1('OffRamp'),
179+
} as Record<string, () => Promise<Cell>>
180180

181181
const upgradeSpec = UpgradeableSpec.newUpgradeSpec({
182-
contractType: OffRampPrev.type(),
183-
prevVersion: of.OFFRAMP_CONTRACT_VERSION_PREV,
182+
contractType: of.OffRamp.type(),
183+
prevVersionConfigs: of.OFFRAMP_SUPPORTED_PREV_VERSIONS.map((version) => ({
184+
version,
185+
getCode: codeLoaders[version],
186+
deploy: async (blockchain: Blockchain, owner: SandboxContract<TreasuryContract>) =>
187+
deployOffRampContract(blockchain, owner, await codeLoaders[version]()),
188+
})),
184189
currentVersion: OffRamp.version(),
185-
getPrevCode: () => OffRampPrev.code(),
186190
getCurrentCode: () => OffRamp.code(),
187191
CurrentVersionConstructor: OffRamp,
188192
upgradeValue: toNano('0.05'),
189-
deployPrevContract: async (blockchain, owner) =>
190-
deployOffRampContract(blockchain, owner, await OffRampPrev.code()),
191193
})
192194
upgradeSpec.run([
193195
{

contracts/tests/ccip/feequoter/FeeQuoter.spec.ts

Lines changed: 13 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import * as ownable2step from '../../../wrappers/libraries/access/Ownable2Step'
1515
import * as fq from '../../../wrappers/ccip/FeeQuoter'
1616
import { Cell, toNano } from '@ton/core'
1717
import { contractCode } from '../../../wrappers/codeLoader'
18-
import { FEE_QUOTER_CONTRACT_VERSION_PREV } from '../../../wrappers/ccip/FeeQuoter'
18+
import { FEE_QUOTER_SUPPORTED_PREV_VERSIONS } from '../../../wrappers/ccip/FeeQuoter'
1919

2020
describe('FeeQuoter - Withdrawable Tests', () => {
2121
const withdrawableSpec = newWithdrawableSpec({
@@ -50,74 +50,31 @@ describe('FeeQuoter - TypeAndVersion Tests', () => {
5050

5151
describe('FeeQuoter - Upgrade Tests', () => {
5252
class FeeQuoter extends fq.FeeQuoter {}
53-
class FeeQuoterPrev extends fq.FeeQuoter {
54-
static code(): Promise<Cell> {
55-
return contractCode.ccip.release_1_6_0('FeeQuoter')
56-
}
57-
}
53+
54+
const codeLoaders = {
55+
'1.6.0': () => contractCode.ccip.release_1_6_0('FeeQuoter'),
56+
'1.6.1': () => contractCode.ccip.release_1_6_1('FeeQuoter'),
57+
} as Record<string, () => Promise<Cell>>
5858

5959
const upgradeSpec = UpgradeableSpec.newUpgradeSpec({
60-
contractType: FeeQuoterPrev.type(),
61-
prevVersion: FEE_QUOTER_CONTRACT_VERSION_PREV,
60+
contractType: fq.FeeQuoter.type(),
61+
prevVersionConfigs: FEE_QUOTER_SUPPORTED_PREV_VERSIONS.map((version) => ({
62+
version,
63+
getCode: codeLoaders[version],
64+
deploy: async (blockchain, owner) =>
65+
setupTestFeeQuoter(owner, blockchain, await codeLoaders[version]()),
66+
})),
6267
currentVersion: FeeQuoter.version(),
63-
getPrevCode: () => FeeQuoterPrev.code(),
6468
getCurrentCode: () => FeeQuoter.code(),
6569
CurrentVersionConstructor: FeeQuoter,
6670
upgradeValue: toNano('0.05'),
67-
deployPrevContract: async (blockchain, owner) =>
68-
setupTestFeeQuoter(owner, blockchain, await FeeQuoterPrev.code()),
6971
})
7072
upgradeSpec.run([
7173
{
7274
code: 'FeeQuoter',
7375
name: 'feequoter',
7476
},
7577
])
76-
77-
it('should change tokenPriceStalenessThreshold on upgrade', async () => {
78-
const blockchain = await Blockchain.create()
79-
const deployer = await blockchain.treasury('deployer')
80-
81-
// deploy prev version
82-
const feeQuoterPrev = await setupTestFeeQuoter(deployer, blockchain, await FeeQuoterPrev.code())
83-
const loadStorage = async () => {
84-
const contract = await blockchain.getContract(feeQuoterPrev.address)
85-
if (!contract.account.account) {
86-
throw new Error('Contract account not found')
87-
}
88-
const storage = contract.account.account.storage
89-
if (storage.state.type != 'active') {
90-
throw new Error('Contract is not active')
91-
}
92-
if (!storage.state.state.data) {
93-
throw new Error('Contract has no data')
94-
}
95-
return fq.builder.data.contractData.load(storage.state.state.data.asSlice())
96-
}
97-
const originalStorage = await loadStorage()
98-
const originalThreshold = originalStorage.tokenPriceStalenessThreshold
99-
const expectedNewThreshold = 86400 // 24 hours in seconds
100-
expect(originalThreshold).not.toBe(expectedNewThreshold) // sanity check
101-
const expectedNewStorage = {
102-
...originalStorage,
103-
tokenPriceStalenessThreshold: expectedNewThreshold,
104-
}
105-
106-
// perform upgrade
107-
const result = await feeQuoterPrev.sendUpgrade(deployer.getSender(), toNano('0.05'), {
108-
queryId: 0n,
109-
code: await FeeQuoter.code(),
110-
})
111-
expect(result.transactions).toHaveTransaction({
112-
from: deployer.address,
113-
to: feeQuoterPrev.address,
114-
success: true,
115-
})
116-
117-
// verify storage was updated
118-
const newStorage = await loadStorage()
119-
expect(newStorage).toEqual(expectedNewStorage)
120-
})
12178
})
12279

12380
describe('FeeQuoter - Ownable Tests', () => {

contracts/tests/examples/versioning/UpgradeableCounter.spec.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,31 @@ async function setUpTest(i: number): Promise<{
6464
describe('UpgradeableCounter - Upgrade Tests', () => {
6565
const upgradeSpec = newUpgradeSpec({
6666
contractType: upCounterV1.ContractClient.type(),
67-
prevVersion: upCounterV1.ContractClient.version(),
67+
prevVersionConfigs: [
68+
{
69+
version: upCounterV1.ContractClient.version(),
70+
getCode: () => upCounterV1.ContractClient.code(),
71+
deploy: async (blockchain, owner) => {
72+
const codeV1 = await upCounterV1.ContractClient.code()
73+
const contract = blockchain.openContract(
74+
upCounterV1.ContractClient.createFromConfig(
75+
{
76+
id: 0,
77+
value: 0,
78+
ownable: { owner: owner.address, pendingOwner: null },
79+
},
80+
codeV1,
81+
),
82+
)
83+
const deployer = await blockchain.treasury('deployer')
84+
await contract.sendDeploy(deployer.getSender(), toNano('0.05'))
85+
return contract
86+
},
87+
},
88+
],
6889
currentVersion: upCounterV2.ContractClient.version(),
69-
getPrevCode: () => upCounterV1.ContractClient.code(),
7090
getCurrentCode: () => upCounterV2.ContractClient.code(),
7191
CurrentVersionConstructor: upCounterV2.ContractClient,
72-
deployPrevContract: async (blockchain, owner) => {
73-
const codeV1 = await upCounterV1.ContractClient.code()
74-
const contract = blockchain.openContract(
75-
upCounterV1.ContractClient.createFromConfig(
76-
{
77-
id: 0,
78-
value: 0,
79-
ownable: { owner: owner.address, pendingOwner: null },
80-
},
81-
codeV1,
82-
),
83-
)
84-
const deployer = await blockchain.treasury('deployer')
85-
await contract.sendDeploy(deployer.getSender(), toNano('0.05'))
86-
return contract
87-
},
8892
})
8993
upgradeSpec.run()
9094
})

0 commit comments

Comments
 (0)