Skip to content

Commit 486931d

Browse files
authored
New FeeToken CS (#254)
* new fee Token * added premium multiplier * comments * nit * rodrigo's feedback * fix go mod
1 parent d9b52a2 commit 486931d

File tree

4 files changed

+140
-4
lines changed

4 files changed

+140
-4
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package changesets
2+
3+
import (
4+
"fmt"
5+
"math/big"
6+
7+
cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment"
8+
"github.com/smartcontractkit/chainlink-deployments-framework/operations"
9+
10+
"github.com/smartcontractkit/chainlink-sui/bindings/bind"
11+
"github.com/smartcontractkit/chainlink-sui/deployment"
12+
sui_ops "github.com/smartcontractkit/chainlink-sui/deployment/ops"
13+
ccipops "github.com/smartcontractkit/chainlink-sui/deployment/ops/ccip"
14+
)
15+
16+
type NewFeeTokenConfig struct {
17+
SuiChainSelector uint64
18+
FeeTokensToRemove []string
19+
FeeTokensToAdd []string // should be the objectID
20+
21+
// update price
22+
SourceUsdPerToken []*big.Int
23+
24+
// premium multiplier wei per eth
25+
PremiumMultiplierWeiPerEth []uint64
26+
}
27+
28+
// ConnectSuiToEVM connects sui chain with EVM
29+
type NewFeeToken struct{}
30+
31+
var _ cldf.ChangeSetV2[NewFeeTokenConfig] = NewFeeToken{}
32+
33+
// Apply implements deployment.ChangeSetV2.
34+
func (d NewFeeToken) Apply(e cldf.Environment, config NewFeeTokenConfig) (cldf.ChangesetOutput, error) {
35+
ab := cldf.NewMemoryAddressBook()
36+
state, err := deployment.LoadOnchainStatesui(e)
37+
if err != nil {
38+
return cldf.ChangesetOutput{}, err
39+
}
40+
41+
seqReports := make([]operations.Report[any, any], 0)
42+
43+
suiChains := e.BlockChains.SuiChains()
44+
suiChain := suiChains[config.SuiChainSelector]
45+
46+
deps := sui_ops.OpTxDeps{
47+
Client: suiChain.Client,
48+
Signer: suiChain.Signer,
49+
GetCallOpts: func() *bind.CallOpts {
50+
b := uint64(400_000_000)
51+
return &bind.CallOpts{
52+
WaitForExecution: true,
53+
GasBudget: &b,
54+
}
55+
},
56+
SuiRPC: suiChain.URL,
57+
}
58+
59+
// Run ApplyFeeTokenUpdate Operation
60+
applyFeeTokenUpdateOP, err := operations.ExecuteOperation(e.OperationsBundle, ccipops.FeeQuoterApplyFeeTokenUpdatesOp, deps, ccipops.FeeQuoterApplyFeeTokenUpdatesInput{
61+
CCIPPackageId: state[suiChain.Selector].CCIPAddress,
62+
StateObjectId: state[suiChain.Selector].CCIPObjectRef,
63+
OwnerCapObjectId: state[suiChain.Selector].CCIPOwnerCapObjectId,
64+
FeeTokensToRemove: config.FeeTokensToRemove,
65+
FeeTokensToAdd: config.FeeTokensToAdd,
66+
})
67+
if err != nil {
68+
return cldf.ChangesetOutput{}, fmt.Errorf("failed to register receiver for Sui chain %d: %w", config.SuiChainSelector, err)
69+
}
70+
71+
seqReports = append(seqReports, []operations.Report[any, any]{applyFeeTokenUpdateOP.ToGenericReport()}...)
72+
73+
// Run ApplyPremiumMultiplier
74+
applyPremiumMultiplierOP, err := operations.ExecuteOperation(e.OperationsBundle, ccipops.FeeQuoterApplyPremiumMultiplierWeiPerEthUpdatesOp, deps, ccipops.FeeQuoterApplyPremiumMultiplierWeiPerEthUpdatesInput{
75+
CCIPPackageId: state[suiChain.Selector].CCIPAddress,
76+
StateObjectId: state[suiChain.Selector].CCIPObjectRef,
77+
OwnerCapObjectId: state[suiChain.Selector].CCIPOwnerCapObjectId,
78+
Tokens: config.FeeTokensToAdd,
79+
PremiumMultiplierWeiPerEth: config.PremiumMultiplierWeiPerEth,
80+
})
81+
if err != nil {
82+
return cldf.ChangesetOutput{}, fmt.Errorf("failed to register receiver for Sui chain %d: %w", config.SuiChainSelector, err)
83+
}
84+
85+
seqReports = append(seqReports, []operations.Report[any, any]{applyPremiumMultiplierOP.ToGenericReport()}...)
86+
87+
return cldf.ChangesetOutput{
88+
AddressBook: ab,
89+
Reports: seqReports,
90+
}, nil
91+
}
92+
93+
// VerifyPreconditions implements deployment.ChangeSetV2.
94+
func (d NewFeeToken) VerifyPreconditions(e cldf.Environment, config NewFeeTokenConfig) error {
95+
return nil
96+
}

deployment/ops/ccip/op_fee_quoter.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,13 @@ var FeeQuoterApplyPremiumMultiplierWeiPerEthUpdatesOp = cld_ops.NewOperation(
402402
type FeeQuoterUpdateTokenPricesInput struct {
403403
CCIPPackageId string
404404
CCIPObjectRef string
405-
FeeQuoterCapId string
406405
SourceTokens []string
407406
SourceUsdPerToken []*big.Int
408407
GasDestChainSelectors []uint64
409408
GasUsdPerUnitGas []*big.Int
409+
410+
FeeQuoterCapId string // optional: only provide if you're running direct UpdateTokenPrice
411+
OwnerCapId string // optional: only provide if you're running UpdateTokenPricesWithOwnerCap
410412
}
411413

412414
var updateTokenPrices = func(b cld_ops.Bundle, deps sui_ops.OpTxDeps, input FeeQuoterUpdateTokenPricesInput) (output sui_ops.OpTxResult[NoObjects], err error) {
@@ -446,6 +448,44 @@ var FeeQuoterUpdateTokenPricesOp = cld_ops.NewOperation(
446448
updateTokenPrices,
447449
)
448450

451+
var updateTokenPricesWithOwnerCap = func(b cld_ops.Bundle, deps sui_ops.OpTxDeps, input FeeQuoterUpdateTokenPricesInput) (output sui_ops.OpTxResult[NoObjects], err error) {
452+
contract, err := module_fee_quoter.NewFeeQuoter(input.CCIPPackageId, deps.Client)
453+
if err != nil {
454+
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to create fee quoter contract: %w", err)
455+
}
456+
457+
opts := deps.GetCallOpts()
458+
opts.Signer = deps.Signer
459+
fmt.Println("INPUTSS: ", input)
460+
tx, err := contract.UpdatePricesWithOwnerCap(
461+
b.GetContext(),
462+
opts,
463+
bind.Object{Id: input.CCIPObjectRef},
464+
bind.Object{Id: input.OwnerCapId},
465+
bind.Object{Id: "0x6"}, // Clock object
466+
input.SourceTokens,
467+
input.SourceUsdPerToken,
468+
input.GasDestChainSelectors,
469+
input.GasUsdPerUnitGas,
470+
)
471+
472+
if err != nil {
473+
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to execute updateTokenPrices on SUI: %w", err)
474+
}
475+
476+
return sui_ops.OpTxResult[NoObjects]{
477+
Digest: tx.Digest,
478+
PackageId: input.CCIPPackageId,
479+
}, err
480+
}
481+
482+
var FeeQuoterUpdateTokenPricesWithOwnerCapOp = cld_ops.NewOperation(
483+
sui_ops.NewSuiOperationName("ccip", "fee_quoter", "update_prices_with_owner_cap"),
484+
semver.MustParse("0.1.0"),
485+
"Apply update prices with ownerCap in CCIP Fee Quoter contract",
486+
updateTokenPricesWithOwnerCap,
487+
)
488+
449489
// FEE QUOTER -- new_fee_quoter_cap
450490
type NewFeeQuoterCapObjects struct {
451491
FeeQuoterCapObjectId string

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/aptos-labs/aptos-go-sdk v1.7.1-0.20250602153733-bb1facae1d43
1212
github.com/aptos-labs/tree-sitter-move-on-aptos v0.0.0-20250321090037-c820eb4716e1
1313
github.com/block-vision/sui-go-sdk v1.1.2
14-
github.com/ethereum/go-ethereum v1.15.7
14+
github.com/ethereum/go-ethereum v1.16.2
1515
github.com/google/uuid v1.6.0
1616
github.com/hashicorp/go-plugin v1.6.3
1717
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
7777
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
7878
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
7979
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
80-
github.com/ethereum/go-ethereum v1.15.7 h1:vm1XXruZVnqtODBgqFaTclzP0xAvCvQIDKyFNUA1JpY=
81-
github.com/ethereum/go-ethereum v1.15.7/go.mod h1:+S9k+jFzlyVTNcYGvqFhzN/SFhI6vA+aOY4T5tLSPL0=
80+
github.com/ethereum/go-ethereum v1.16.2 h1:VDHqj86DaQiMpnMgc7l0rwZTg0FRmlz74yupSG5SnzI=
81+
github.com/ethereum/go-ethereum v1.16.2/go.mod h1:X5CIOyo8SuK1Q5GnaEizQVLHT/DfsiGWuNeVdQcEMNA=
8282
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
8383
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
8484
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=

0 commit comments

Comments
 (0)